Getting row number in User Control that place inside DataGrid

J

John Shum

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 ?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top