在子网格中编辑 [英] Editing in Child Grid
本文介绍了在子网格中编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何编辑,更新我的子网格行. 我使用Temprory DataTable绑定我的子网格.
谁能建议我解决这个问题...
Hi,
How can i edit,update my child Grid Rows. I bind My child Grid using Temprory DataTable.
can any body suggest me to solve this issue...
推荐答案
//从子网格页脚添加记录的代码
受保护的void gvChild_RowCommand(object sender,GridViewCommandEventArgs e)
{
DataTable dt = ViewState ["dt"] as DataTable;
DataTable dtCity = new DataTable();
dtCity = ViewState ["ddl"]作为DataTable;
GridView gvChild =(GridView)((LinkButton)e.CommandSource).NamingContainer.Parent.Parent;
如果(e.CommandName =="AddChild")
{
TextBox txtName =(TextBox)gvChild.FooterRow.FindControl("txtName");
DropDownList ddlCity =(DropDownList)gvChild.FooterRow.FindControl("ddlCity");
dt.Rows.Add(txtName.Text,ddlCity.SelectedValue);
ViewState ["dt"] = dt;
gvChild.DataSource = dt;
gvChild.DataBind();
ddlCity.DataSource = dtCity;//如果您的子网格页脚中有下拉菜单
ddlCity.DataValueField =城市";
ddlCity.DataTextField =城市";
ddlCity.DataBind();
}
}
// Code for adding record from child grid footer
protected void gvChild_RowCommand(object sender, GridViewCommandEventArgs e)
{
DataTable dt = ViewState["dt"] as DataTable;
DataTable dtCity = new DataTable();
dtCity = ViewState["ddl"] as DataTable;
GridView gvChild = (GridView)((LinkButton)e.CommandSource).NamingContainer.Parent.Parent;
if (e.CommandName == "AddChild")
{
TextBox txtName = (TextBox)gvChild.FooterRow.FindControl("txtName");
DropDownList ddlCity = (DropDownList)gvChild.FooterRow.FindControl("ddlCity");
dt.Rows.Add(txtName.Text, ddlCity.SelectedValue);
ViewState["dt"] = dt;
gvChild.DataSource = dt;
gvChild.DataBind();
ddlCity.DataSource = dtCity;// If u have dropdown in your child grid footer
ddlCity.DataValueField = "City";
ddlCity.DataTextField = "City";
ddlCity.DataBind();
}
}
U可以对子网格的rowcommand事件执行操作.在rowcommand事件中检查命令名称并执行操作.
U can do on rowcommand event of child grid .in rowcommand event check command name and perform operation .
这篇关于在子网格中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文