text from DataGrid
-
hi everybody I have a textbox in Datagrid > and i want to get text from this textbox foreach(DataGridItem xItem in DGUpdateStudents.Items) { clsobj.StudentId = DGUpdateStudents.DataKeyField[xItem.ItemIndex]; clsobj.ForeName=(String) ((TextBox)xItem.FindControl("TxtForeName")).Text; } no error but doesnot return text from textbox like if enter name like John it returns me "" empty strings. thanks in adv for help.
-
hi everybody I have a textbox in Datagrid > and i want to get text from this textbox foreach(DataGridItem xItem in DGUpdateStudents.Items) { clsobj.StudentId = DGUpdateStudents.DataKeyField[xItem.ItemIndex]; clsobj.ForeName=(String) ((TextBox)xItem.FindControl("TxtForeName")).Text; } no error but doesnot return text from textbox like if enter name like John it returns me "" empty strings. thanks in adv for help.
Are you binding the grid in
page_load
and binding without checkingIsPostBack
?Learner520 wrote:
(String) ((TextBox)xItem.FindControl("TxtForeName")).Text;
This is bad practice. If your item can't be found, this code will crash. First find the control, do
NULL
checking and ensure you have a valid object before you accessText
property on it. :)Navaneeth How to use google | Ask smart questions