my problem is i can't retrieve data from my sqldatasource to be displayed in textbox... i try to do it in vb codes. somebody help me here?
Hi firefox3000,
First i would suggest you posting your code here so we can better help you.
And second, what do you mean by "can't retrieve data from my sqldatasource to be displayed in textbox". Do you mean you cannot retrieve data from sqldatasource OR you can get the data but you cannot get them dispalyed? Easiest way is to set up a break point after retrieving data though database query and see if the data has been populated.
If you cannot get the data, tryado.net stuff and if cannot get those data displayed, check if you have bound your textbox.text property to a wrong place.
Hope my suggestion helps
|||Hello Bo Chen,
I think I can't retrieve my data from my sqldatasource. Pls check my code:
Imports SystemImports System.DataImports System.ConfigurationImports System.WebImports System.Web.SecurityImports System.Web.UIImports System.Web.UI.WebControlsImports System.Web.UI.WebControls.WebPartsImports System.Web.UI.HtmlControlsImports Telerik.WebControlsImports System.Data.SqlClientImports Telerik.WebControls.GridEditFormItemImports System.Data.SqlTypesPartialClass _DefaultInherits System.Web.UI.PagePublic Shared dtTableAs New DataTablePublic sqlConnectionAs New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString())Public sqlAdapterAs New SqlDataAdapter()Public sqlCommandAs New SqlCommand()Protected Sub RadGrid1_NeedDataSource(ByVal sourceAs Object,ByVal eAs Telerik.WebControls.GridNeedDataSourceEventArgs)Handles RadGrid1.NeedDataSource sqlConnection.Open()Dim queryAs String ="SELECT * FROM blogpost" sqlAdapter.SelectCommand =New SqlCommand(query, sqlConnection) sqlAdapter.Fill(dtTable) RadGrid1.DataSource = dtTable sqlConnection.Close()End Sub Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load'Dim txt As Label 'For Each item As GridDataItem In RadGrid1.Items 'txt = CType(Item("TemplateColumn").FindControl("Label1"), Label) 'MsgBox(txt.Text) 'Next 'Dim txt As Label = CType(RadGrid1.Items.Item("TemplateColumn").FindControl("Label1"), Label)End Sub Protected Sub RadGrid1_ItemDataBound(ByVal senderAs Object,ByVal eAs Telerik.WebControls.GridItemEventArgs)Handles RadGrid1.ItemDataBound'If TypeOf e.Item Is GridDataItem Then 'Dim dataitem As GridDataItem = TryCast(e.Item, GridDataItem) 'Find the control in the template column using the find control method 'Dim TextBox1 As Label = DirectCast(dataitem("TemplateColumn").FindControl("Label1"), Label) 'MsgBox(TextBox1.Text) 'End If sqlConnection.Open()Dim queryAs String ="SELECT * FROM blogpost" sqlAdapter.SelectCommand =New SqlCommand(query, sqlConnection) sqlAdapter.Fill(dtTable)Dim userControlAs UserControl = TryCast(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)If TypeOf e.ItemIs GridDataItemThen Dim dataItemAs GridDataItem = TryCast(e.Item, GridDataItem)Dim lblDateTimeAs Label =CType(dataItem.FindControl("Label1"), Label)Dim divContentAs HtmlGenericControl =CType(dataItem.FindControl("blog"), HtmlGenericControl)Dim lblPostedByAs Label =CType(dataItem.FindControl("Label2"), Label) lblDateTime.Text = dtTable'''' I dont know how to do it here....End If sqlConnection.Close()End SubEnd Class|||
Hi firefox3000,
Sorry i didn't know your talbe structure so i cannot give you an accurate answer.
Your code should look like this:
lblDateTime.Text = dtTable'''' I dont know how to do it here....
lblDataTime.Text=dtTable[rownumber][colnumber].ToString();
Any further issues, please let me know. thanks
|||Hi Bo Chen,
In rownumber or colnumber, can i make it a name of my field in my table?
table:
id - int
title - varchar
blog - varchar
datetime - datetime
lblDateTime.Text = dtTable(0)("title")
is that possible?
No comments:
Post a Comment