DataGrid FindControl HELP...

Discussion in 'ASP .Net' started by Mike Speak, Nov 19, 2003.

  1. Mike Speak

    Mike Speak Guest

    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
     
    Mike Speak, Nov 19, 2003
    #1
    1. Advertising

  2. Mike Speak

    Mike Speak Guest

    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 :-(

    (Mike Speak) wrote in message news:<>...
    > 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
     
    Mike Speak, Nov 19, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sid
    Replies:
    4
    Views:
    598
  2. Dave

    Datagrid FindControl in Footer

    Dave, Nov 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,080
  3. Ruby

    findcontrol in datagrid footer

    Ruby, Jan 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,825
  4. =?Utf-8?B?Qkc=?=
    Replies:
    0
    Views:
    811
    =?Utf-8?B?Qkc=?=
    Dec 27, 2004
  5. Terry Olsen

    Need help with FindControl in DataGrid

    Terry Olsen, May 2, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    10,692
    Terry Olsen
    May 3, 2005
Loading...

Share This Page