I have created gridview dynamically on click event of button.I have 4 fields per row(First name,last name, relation,DOB) with link button for add(lnkadd).I used Itemtemplate, edittemplate, EditItemTemplate, FooterTemplate to design gridview. I used function to add rows to gridview in lnkadd click event as follows:
tabemp = (DataTable)Session["tabempsession"];
if (tabemp.Rows.Count == 1)
{
if (Convert.ToString(tabemp.Rows[0].ItemArray.GetValue(0)) == "")
{
tabemp.Rows.Clear();
}
}
DataRow drow = tabemp.NewRow();
//create new veriable of(textbox,dropdownlist etc) in ItemTemplate in grid view
TextBox txtFName1 = (TextBox)mygridview.FooterRow.FindControl("txtFName1");
TextBox txtLName1 = (TextBox)mygridview.FooterRow.FindControl("txtLName1");
DropDownList ddlRelation = (DropDownList)mygridview.FooterRow.FindControl("ddlRelation");
TextBox txtDOB = (TextBox)mygridview.FooterRow.FindControl("txtDOB");
//insert values into rows in tabemp table
drow[0] = txtFName1.Text;
drow[1] = txtLName1.Text;
drow[2] = ddlRelation.SelectedItem.Text;
drow[3] = txtDOB.Text;
tabemp.Rows.Add(drow);
Session["tabempsession"] = tabemp;
//int f = tabemp.Rows.Count;
mygridview.DataSource = (DataTable)Session["tabempsession"];
mygridview.DataBind();
But i am not getting textbox values .ie(txtFName1.Text), its getting as null. Please give me suggestion for getting values of all controls inside gridview. Asp.net C# Thank you.