我正在使用嵌套网格视图方案。我怎么发现我的Child网格视图的OnRowCommand没有在父网格视图中触发。我冲浪并找到了一个解决方案like。 实施此后我没有任何效果。我的子网格视图OnRowCommand没有被解雇
有关更多信息,请放置我的代码:
protected void GV_ViewServices_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header && this.ViewState["SortExp"] != null)
{
System.Web.UI.WebControls.Image ImgSort = new System.Web.UI.WebControls.Image();
if (this.ViewState["SortOrder"].Equals("ASC"))
ImgSort.ImageUrl = "../images/down_arrow_1.gif";
else
ImgSort.ImageUrl = "~/images/up_arrow_1.gif";
switch (this.ViewState["SortExp"].ToString())
{
case "Service_name":
PlaceHolder placeholderServiceName = (PlaceHolder)e.Row.FindControl("placeholderServiceName");
placeholderServiceName.Controls.Add(ImgSort);
break;
case "IsActive":
PlaceHolder placeholderstatus = (PlaceHolder)e.Row.FindControl("placeholderstatus");
placeholderstatus.Controls.Add(ImgSort);
break;
case "Service_desc":
PlaceHolder placeholderdescription = (PlaceHolder)e.Row.FindControl("placeholderdescription");
placeholderdescription.Controls.Add(ImgSort);
break;
case "Created_date":
PlaceHolder placeholderdate = (PlaceHolder)e.Row.FindControl("placeholderdate");
placeholderdate.Controls.Add(ImgSort);
break;
}
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Web.UI.WebControls.GridView GV_ViewServiceFeature = (System.Web.UI.WebControls.GridView)e.Row.FindControl("GV_ViewServiceFeature");
if (Session["ChildPageIndex"] != null)
{
DataTable dtPageIndex = (DataTable)Session["ChildPageIndex"];
GV_ViewServiceFeature.PageIndex = Convert.ToInt16(dtPageIndex.Rows[e.Row.RowIndex][0]);
}
FillFeatureGrid(int.Parse(GV_ViewServices.DataKeys[e.Row.RowIndex].Value.ToString()), GV_ViewServiceFeature);
System.Web.UI.WebControls.GridView GV_ViewServiceCharge = (System.Web.UI.WebControls.GridView)e.Row.FindControl("GV_ViewServiceCharge");
if (Session["ChildPageIndex"] != null)
{
DataTable dtPageIndex = (DataTable)Session["ChildPageIndex"];
GV_ViewServiceCharge.PageIndex = Convert.ToInt16(dtPageIndex.Rows[e.Row.RowIndex][0]);
}
FillChargeGrid(int.Parse(GV_ViewServices.DataKeys[e.Row.RowIndex].Value.ToString()), GV_ViewServiceCharge);
}
}
protected void GV_ViewServiceFeature_RowCommand(object sender, GridViewCommandEventArgs e)
{
foreach(GridViewRow row in GV_ViewServices.Rows)
{
GridView gv=row.FindControl("GV_ViewServiceFeature") as GridView;
if (e.CommandName.Equals("AddNew") && Page.IsValid)
{
TextBox txtfeaturetext = (TextBox)gv.FooterRow.FindControl("txtfeaturetext");
int returnValue = DatabaseHelper.AddNewServiceFeature(int.Parse(service_id.Value.ToString()), txtfeaturetext.Text.Trim());
if (returnValue > 0)
{
this.FillFeatureGrid(int.Parse(GV_ViewServices.DataKeys[row.RowIndex].Value.ToString()),gv);
}
}
int intCurIndex = gv.PageIndex;
switch (e.CommandArgument.ToString().ToLower())
{
case "first":
gv.PageIndex = 0;
break;
case "prev":
CurrentPage -= 1;
break;
case "next":
CurrentPage += 1;
break;
case "last":
gv.PageIndex = gv.PageCount;
break;
}
this.FillFeatureGrid(int.Parse(GV_ViewServices.DataKeys[row.RowIndex].Value.ToString()), gv);
}
}
请帮我解决这个问题。
答案 0 :(得分:0)
首先我们必须在父网格视图row_created事件中手动注册命令。
protected void GV_ViewServices_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gv = e.Row.FindControl("GV_ViewServiceFeature") as GridView;
gv.RowCommand += new GridViewCommandEventHandler(GV_ViewServiceFeature_RowCommand);
GridView gv1 = e.Row.FindControl("GV_ViewServiceCharge") as GridView;
gv1.RowCommand += new GridViewCommandEventHandler(GV_ViewServiceCharge_RowCommand);
}
}
protected void GV_ViewServiceFeature_RowCommand(object sender, GridViewCommandEventArgs e)
{
System.Web.UI.WebControls.GridView gv = ((System.Web.UI.WebControls.GridView)sender);
GridViewRow gvRowParent = ((System.Web.UI.WebControls.GridView)sender).Parent.Parent.Parent.Parent as GridViewRow;
if (e.CommandName.Equals("AddNew"))
{
Page.Validate("AddNewFeature");
TextBox txtfeaturetext = (TextBox)gv.FooterRow.FindControl("txtfeaturetext");
int returnValue = DatabaseHelper.AddNewServiceFeature(int.Parse(GV_ViewServices.DataKeys[gvRowParent.RowIndex].Value.ToString()), txtfeaturetext.Text.Trim());
if (returnValue > 0)
{
this.FillFeatureGrid(int.Parse(GV_ViewServices.DataKeys[gvRowParent.RowIndex].Value.ToString()), gv);
}
}
int intCurIndex = gv.PageIndex;
switch (e.CommandArgument.ToString().ToLower())
{
case "first":
gv.PageIndex = 0;
break;
case "prev":
CurrentPage -= 1;
break;
case "next":
CurrentPage += 1;
break;
case "last":
gv.PageIndex = gv.PageCount;
break;
}
this.FillFeatureGrid(int.Parse(GV_ViewServices.DataKeys[gvRowParent.RowIndex].Value.ToString()),gv);
}