find runtime textbox value from grid
-
I create a gridview with runtime columns. after that add textbox in this column. Here the code. protected void grdOne_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TemplateField T = new TemplateField(); grdOne.Columns.Add(T); GridViewRow gvr = e.Row; TableCell tcell = new TableCell(); for (Int32 i = 0; i < columnCounter; i++) { TextBox tb = new TextBox(); tb.Width = 30; tb.Text = "0"; tb.ID = "tb_" + i.ToString(); tcell.Controls.Add(tb); } gvr.Cells.Add(tcell); grdOne.Controls[0].Controls.AddAt(0, gvr); } } But when i fetch textbox value from this grid that comes with error. can any one tell me how to fetch textbox value from my grid m using these line of code to fetch textbox values public void GetArray(GridView grd) { String[,] ar = new String[rowCounter, columnCounter]; for (int i = 0; i < grd.Rows.Count; i++) { for( int j=1; j<= grd.Columns.Count; j++) { String tId = "grdOne_ctl03_tb_" + j.ToString(); String t = ((DataControlFieldCell)(grd.Rows[i].FindControl()).text; } } }
-
I create a gridview with runtime columns. after that add textbox in this column. Here the code. protected void grdOne_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TemplateField T = new TemplateField(); grdOne.Columns.Add(T); GridViewRow gvr = e.Row; TableCell tcell = new TableCell(); for (Int32 i = 0; i < columnCounter; i++) { TextBox tb = new TextBox(); tb.Width = 30; tb.Text = "0"; tb.ID = "tb_" + i.ToString(); tcell.Controls.Add(tb); } gvr.Cells.Add(tcell); grdOne.Controls[0].Controls.AddAt(0, gvr); } } But when i fetch textbox value from this grid that comes with error. can any one tell me how to fetch textbox value from my grid m using these line of code to fetch textbox values public void GetArray(GridView grd) { String[,] ar = new String[rowCounter, columnCounter]; for (int i = 0; i < grd.Rows.Count; i++) { for( int j=1; j<= grd.Columns.Count; j++) { String tId = "grdOne_ctl03_tb_" + j.ToString(); String t = ((DataControlFieldCell)(grd.Rows[i].FindControl()).text; } } }
Something issue with control Id, it's not able to find the exact control id. It may be issue with control hierarchy. I have some suggestion for you: 1. If you want to follow the same code then view the page source and see what is name of control id and under which parent control has created. 2. Other way, Create a template column at design time and put there a panel. On runtime find the panel and add the all textbox control inside the panel. same way, during retrieval find the Panel and traverse the all child control. Thanks,
Parwej Ahamad ahamad.parwej@gmail.com