C# 关于在asp.net c中向动态创建的gridview插入记录#
我已经在按钮的点击事件中动态创建了gridview。我每行有4个字段(名字、姓氏、关系、DOB),带有用于添加的链接按钮(lnkadd)。我使用Itemtemplate、edittemplate、EditItemTemplate、FooterTemplate来设计gridview。 我使用函数在lnkadd click事件中将行添加到gridview,如下所示:C# 关于在asp.net c中向动态创建的gridview插入记录#,c#,asp.net,C#,Asp.net,我已经在按钮的点击事件中动态创建了gridview。我每行有4个字段(名字、姓氏、关系、DOB),带有用于添加的链接按钮(lnkadd)。我使用Itemtemplate、edittemplate、EditItemTemplate、FooterTemplate来设计gridview。 我使用函数在lnkadd click事件中将行添加到gridview,如下所示: tabemp = (DataTable)Session["tabempsession"]; if (tabemp.
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();
但是我没有得到textbox的值。请给我一些建议,以获取gridview中所有控件的值。
Asp.NETC#
多谢各位 据我猜测,原因是您在回发过程中丢失了数据。i、 e.开始时,您的网格已填充,但当您单击按钮时,页面将被发回,并且在发回后,网格显示为新网格。尝试使用(!isPostBack)。我不确定,但这可能有助于您了解提示。逐步完成代码。我猜FindControl找不到该控件。如果使用(!ispostback),则gridview不可见