473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Accessing label inside headertemplates

<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Font-Names="Verdana, Arial, Helvetica,
sans-serif"
AllowCustomPaging="True" GridLines="Horizontal">
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Teal"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b><asp:label id="lblHeadline" Runat="server"></asp:label></b>
</HeaderTemplate>
<ItemTemplate>
and so on...
HOW???
Can I access lblHeadline from codebehind?

I got some answer before that you should use Findcontrol...
I can believe that this is the right answer, but I simply can´t find that
control...
I tryed:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Dim tmpCtrl As Object
'tmpCtrl = e.Item.FindControl("lblHeadline")
tmpCtrl = DataGrid1.FindControl("lblHeadline")
tmpCtrl .Text = "HELLO!"
End Sub

but, I simply can not find the damn thing...
I believe that the reason is that it is lying behind a asp:templatecolumn,
but I tryed to put an id on that but my VS simply dont want me to... :(

Any suggestions on how to find this label?

Yours: Kristoffer
Nov 18 '05 #1
1 1041
FOUND IT!!!

Never mind, my question I found it...

I did it by using the following code...

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Header) Then
Dim i As Integer
For i = 0 To e.Item.Controls.Count - 1
Try
If (e.Item.Controls(i).Controls(1).GetType().ToString ()
= "System.Web.UI.WebControls.Label") Then
Dim tb As Label
tb = e.Item.Controls(i).Controls(1)
tb.Text = "TJABBA!"
End If
Catch

End Try
Next
End If
End Sub

Maybe not the best code, and especially if you have multiple controls, but I
only have one, so this works for me for now, if you guys have any better
suggestions, please share...

Yours: Kristoffer

"Kristoffer Arfvidson" <kr********@spamtrap.com> skrev i meddelandet
news:ee**************@TK2MSFTNGP11.phx.gbl...
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Font-Names="Verdana, Arial, Helvetica,
sans-serif"
AllowCustomPaging="True" GridLines="Horizontal">
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="Teal"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b><asp:label id="lblHeadline" Runat="server"></asp:label></b>
</HeaderTemplate>
<ItemTemplate>
and so on...
HOW???
Can I access lblHeadline from codebehind?

I got some answer before that you should use Findcontrol...
I can believe that this is the right answer, but I simply can´t find that
control...
I tryed:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Dim tmpCtrl As Object
'tmpCtrl = e.Item.FindControl("lblHeadline")
tmpCtrl = DataGrid1.FindControl("lblHeadline")
tmpCtrl .Text = "HELLO!"
End Sub

but, I simply can not find the damn thing...
I believe that the reason is that it is lying behind a asp:templatecolumn,
but I tryed to put an id on that but my VS simply dont want me to... :(

Any suggestions on how to find this label?

Yours: Kristoffer

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Knoop | last post by:
Hi all I have a page that contains a label (<asp:label id="lbl" runat="server">). Further down in that same page, I include the contents of a different page using Server.Execute. Now, I need...
2
by: bredal Jensen | last post by:
Hello there, I need to show or hide a label cotrol in one of the cell of my datagrid. I tried the following: ---------- DataGridItem item = MyDataGrid.Items;
0
by: RichardF | last post by:
I have a solution that contains a web service and a web site. I was working on it all day Monday with no problems. Tuesday morning it stopped working, but ONLY when run from inside Visual...
0
by: Moojjoo | last post by:
OK fellow developers... I am running into a new problem. I have developed a datalist Inside the datalist I have a label What I want to do is set the label value using a class I developed. ...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
2
by: premchandrasingh | last post by:
Hi I am using a master page in which I have only one contentplaceholder and inside this contentplaceholder I added a label. The problem is when I tried to assign some value to this label from...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: damnBoi | last post by:
Good day guys! I'm using c# as my code-behind (ascx.cs) and my environment is Visual Studio 2008. the issue is, i can't get to access labels inside the gridview.. my gridview definition is:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.