Getting row number in User Control that place inside DataGrid

Discussion in 'ASP .Net' started by John Shum, Oct 10, 2005.

  1. John Shum

    John Shum Guest

    I prepare a UserControl that act as a lookup control, once the code is
    enter in the TextBox, the description will appear in another TextBox
    outside the UserControl of the same row in a DataGrid via javascript.

    I attempt to get the client ID of the TextBox (with provided ID of that
    TextBox as "ext_desc") by the following code inside the Page_Load()
    event of the UserControl (named Color_Control):

    for(int i = 0; i < DataGrid1.Items.Count; i++)
    {

    if(((Color_Control)DataGrid1.Items.FindControl(this.ID)).Equals(sender))
    {
    desc_obj =
    ((TextBox)DataGrid1.Items.FindControl(ext_desc)).ClientID;
    break;
    }
    }

    desc_obj should get the ClientID of the TextBox.
    It run okay when I run the page at first time, but when I write a code
    to append some empty rows inside the DataGrid again, it fail to get the
    number of Control, the code for adding empty rows is as follow:

    // In the Page that the User Control located
    private void Add_Click(object sender, System.EventArgs e)
    {
    DataRow dr ;
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("item_attr_x_code", typeof(string)));
    for (int i = 0; i < color.Items.Count; i++)
    {
    dr = dt.NewRow();
    dr[0] =
    ((Common.Color_Control)DataGrid1.Items.FindControl("Color_Control_grid")).Code;
    dt.Rows.Add(dr);
    }

    for (int k=1; k <= 5; k++)
    {
    dr = dt.NewRow();
    dr[0] = "";
    dt.Rows.Add(dr);
    }
    DataGrid1.DataSource = dsX;
    DataGrid1.DataBind();
    }

    It seems that after the above function is executed, the
    DataGrid1.Items.Count inside the Page_Load Event of the UserControl
    fail to get the correct Items.Count.

    May I know if there is any work around on the case, or I start from a
    wrong approach ?
     
    John Shum, Oct 10, 2005
    #1
    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. 2obvious

    getting the row number in a datagrid

    2obvious, Dec 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,509
    2obvious
    Dec 31, 2004
  2. Luis Esteban Valencia

    Make a DataGrid row editable after user selects the row

    Luis Esteban Valencia, Jan 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    357
    Luis Esteban Valencia
    Jan 12, 2005
  3. Keefe Goldfisher via .NET 247

    Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns

    Keefe Goldfisher via .NET 247, Mar 7, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    188
    Keefe Goldfisher via .NET 247
    Mar 7, 2005
  4. D
    Replies:
    0
    Views:
    229
  5. Kiran More
    Replies:
    2
    Views:
    326
    Kiran More
    Nov 14, 2006
Loading...

Share This Page