Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hide certain labels in datalist

Status
Not open for further replies.

Zarcom

Programmer
May 7, 2002
1,275
CA
I gots me a doozer.
I have a datalist that is filled with numeric data. I set the templates to load that data into labels. I was wondering if it is possible to loop through the corresponding dataset and hide the proper label if the value in the dataset is 0.

Ex

for each row in dataset
if row.num = 0 then
'hide lblTax1 in datalist that displays this record
end if
Next


I am kinda stumped here so if you can help you'll get a big kiss... well maybe a star instead
[peace]
 
I'm no expert on datalists, but for any control can't you just do control.visible=false ? I must be missing something... Chris
 
yes and no
that is exactly what I want to do however how do I get the control name? in a datalist I can't seem to find how to do this. [peace]
 
You should be able to access your controls of teh datalist from the ItemCreated Event of the DataList.

[in c#]

private void DataList1_ItemCreated(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
for each row in ds
{
if (row.num = 0)
{
lblTax1.Visible = false;
}
}
}

hope it works!

 
make that for each statement like this:

foreach (DataRow row in ds)
{
if (row.num = 0)
{
lblTax1.Visible = false;
}
}

sorry for the mistake :p
 
It doesn't seem that that will work. The label is still not visible to the function for one. as well the item_created function is called before the databind. Because of this I can't check the specific label. [peace]
 
OMG [PC]
I can't beleive it took me two days to get this ARRGGG.

Dim I As Long

For I = 0 To DataList1.Items.Count - 1

Dim myLabel As Label
myLabel = DataList1.Items(I).FindControl("lblTax1")

If myLabel.Text = "$0.00" Then
myLabel.Visible = False
End If
Next


burnt out techy [peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top