Controls not recognized in the code behind file.

S

SWATHI ALLU

Hi, I am having a problem thats really driving me nuts, i have a datagrid
and one of the labels is initialised with a database value
using the <%#Container.DataItem("something") %>

now when i do this, the code behind file is not recognizing the label
control. Any work arounds for this?

thanks in advance

-K
 
K

Ken Cox [Microsoft MVP]

You didn't show your server-side code, but the asp.net code should look
something like this:

<asp:TemplateColumn HeaderText="Label">
<ItemTemplate>
<asp:Label id="Label1" runat="server"
Text='<%#Container.DataItem("FirstName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim lbl As Label
lbl = e.Item.FindControl("Label1")
If Not IsNothing(lbl) Then
lbl.Text = "Hello..." & lbl.Text
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top