handling table and its row in code behindNRnishant ranjan12yAsked Jan 20, 2014, 4:14 AM6k.NET i have a table with row and controls.is there any way by which we can know in which row number does control txtName or txtAddress fall or in row 1 which controls are there by accessing table at runtime i.e., in code page. either way will do. is it possible? if so then how can we do it
Jaganathan Bantheswaran12y agoPosted Jan 20, 2014, 6:44 AMAccepted answerSimple function [Source] to find the control, [your control should have id as wel as runat="server"]public static Control DeepFindControl(Control c, string id){ if (c.ID == id) { return c; } if (c.HasControls) { Control temp; foreach (var subcontrol in c.Controls) { temp = DeepFindControl(subcontrol, id); if (temp != null) { return temp; } } } return null;}Or simply loop like,var table = tblMyTable as HtmlTable;string str; for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Rows[i].Cells.Count; j++) { // Use FindControl function here... } }0
NRnishant ranjan12y agoPosted Jan 20, 2014, 6:19 AMok.. but how can i get controls id in each row wise. means all the control in that row say row1or say i have control id and i want to know in which row number it exist.0
Jaganathan Bantheswaran12y agoPosted Jan 20, 2014, 6:06 AMHi,If you want to access the html control say table in aspx code behind, you have to use runat="server" attribute in the html table.Example....On server side you can access it by using the variable tblMyTable0
Jaganathan BantheswaranPosted Jan 20, 2014, 6:44 AM
public static Control DeepFindControl(Control c, string id)
{
if (c.ID == id)
{
return c;
}
if (c.HasControls)
{
Control temp;
foreach (var subcontrol in c.Controls)
{
temp = DeepFindControl(subcontrol, id);
if (temp != null)
{
return temp;
}
}
}
return null;
}
Or simply loop like,
var table = tblMyTable as HtmlTable;
string str;
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
// Use FindControl function here...
}
}
nishant ranjanPosted Jan 20, 2014, 7:47 AM
nishant ranjanPosted Jan 20, 2014, 6:19 AM
or say
i have control id and i want to know in which row number it exist.
Jaganathan BantheswaranPosted Jan 20, 2014, 6:06 AM
If you want to access the html control say table in aspx code behind, you have to use runat="server" attribute in the html table.
Example
....
On server side you can access it by using the variable tblMyTable