0

ネストされたグリッド ビューのシナリオで作業しています。子グリッド ビューの OnRowCommand が親グリッド ビュー内で起動されないことがわかりました。私はサーフィンをしていて、のような解決策を見つけました。これを実装した後、私は効果がありません。まだ私の子グリッドビューの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);
        }
    }

この問題を解決してください。

4

1 に答える 1

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);
    }
于 2013-05-04T07:10:12.650 に答える