DataGrid FindControl HELP...

  • Thread starter Thread starter Mike Speak
  • Start date Start date
M

Mike Speak

On my page_load, I am populating a Datagrid through the normal manner
(which works) before attempting to pick out the items in one column to
use in another part of my page. This is all within page_load.

Within my Datagrid I have an <ItemTemplate/> tag with a child
<asp:Label/> tag. The ID on the <asp:Label/> tag is set to
"lblDescription".

I am using the following code to iterate over the DataGrid control and
pick out the descriptions I am after: This is being called AFTER the
DataBind method has been called on the DataGrid:

string productList = "";

for (int i=0; i < dataList.Items.Count; i++)
{
Label desc = (Label) dataList.Items.FindControl("lblDescription");
productList = desc.Text + ", ";
}

return productList;

However, FindControl does not seem to find the control I am after. It
always returns null.

I have used the exact same method on another page with the only
difference being I am searching for a TextBox and that works fine.

I noticed (viewing source) that on the other page that works, the id
of the text box control is rendered as an <input/> tag with the name
attribute set to "dataList:_ctl2:txtQuantity".

The page where I want to retrieve the label, the Label control is
being rendered as a <span/> with an "id" attribute with the value
"dataList__ctl2_lblDescription" - there is no "name" attr.

Can anyone help me. I would be most grateful if any guru out there can
shed any light on my problem.

Thanking you most kindly
Mike
 
Can anyone help with this problem??? (PLEASE)

It works when searching for a TextBox within a datagrid, I assumed it
would also work for asp:Labels - but it's not...

PLEASE HELP SOMEONE :-(
 
Back
Top