By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,180 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,180 IT Pros & Developers. It's quick & easy.

Getting row number in User Control that place inside DataGrid

P: n/a
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[i].FindControl(this.ID)).Equals(sender))
{
desc_obj =
((TextBox)DataGrid1.Items[i].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[i].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 ?

Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.