DataGrid Footer

G

Guest

How to find a control in the datagrid footer ?

In my code below, I am trying to hide a label named lbl1 on the basis of a selected vlaue(value="test") of the dropdownlist ,both the dropdownlist and the label are in the footer of the datagrid.

An advice on where I am going wrong,would be highly appreciated

For Each datagriditem In dg1.Items
Dim str as string="test" 'this gives the value of selected item from the dropdown list in the footer
If datagriditem.ItemType = ListItemType.Footer Then
Dim lbl As New Label
lbl = CType(datagriditem.FindControl("lbl1"), Label)
If str = "test" Then
lbl.Visible = False
End If
End If
Next



Rgds
Shiju
 
S

Scott Allen

Hi Shiju:

See my article here:
http://odetocode.com/Articles/116.aspx

The code is in C#, but you should be able to find a technique to use
from the description and code, which includes finding controls in a
grid footer and header. The trick is this: the Items collection only
contains data bound items, for the header and footer you need to look
in the Controls collection.

HTH,
 
J

John Saunders

Shiju Poyilil said:
How to find a control in the datagrid footer ?

In my code below, I am trying to hide a label named lbl1 on the basis of a
selected vlaue(value="test") of the dropdownlist ,both the dropdownlist and
the label are in the footer of the datagrid.
An advice on where I am going wrong,would be highly appreciated

For Each datagriditem In dg1.Items
Dim str as string="test" 'this gives the value of selected
item from the dropdown list in the footer
If datagriditem.ItemType = ListItemType.Footer Then
Dim lbl As New Label
lbl = CType(datagriditem.FindControl("lbl1"), Label)
If str = "test" Then
lbl.Visible = False
End If
End If
Next

For one thing, you do not want to use "New Label". That creates a new label.
Just say "Dim lbl As Label".

Also, you don't say what problem you have with the above code.
 
G

Guest

thanks Scott, it helped me .

Scott Allen said:
Hi Shiju:

See my article here:
http://odetocode.com/Articles/116.aspx

The code is in C#, but you should be able to find a technique to use
from the description and code, which includes finding controls in a
grid footer and header. The trick is this: the Items collection only
contains data bound items, for the header and footer you need to look
in the Controls collection.

HTH,
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top