• ASP.NET Gridview数据库绑定支持增删改,记得要完整实现


    1.错误情况

    /WebSite3”应用程序中的服务器错误。

    指定的参数已超出有效值的范围。
    参数名: index

    说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

    异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
    参数名: index

    源错误: 

    行 26:     {
    行 27:         MyClass.Alert(e.RowIndex.ToString()+"1111111");   
    行 28:         string id = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim();
    行 29:         string fatherID = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
    行 30:         string thisTitle = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();

    源文件: g:备份Visual Studio 2010WebSitesWebSite3AdminMenuManage.aspx.cs    行: 28 

    堆栈跟踪: 

    [ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
    参数名: index]
       System.Web.UI.ControlCollection.get_Item(Int32 index) +9601258
       Admin_MenuManage.GvMenu_RowUpdating(Object sender, GridViewUpdateEventArgs e) in g:备份Visual Studio 2010WebSitesWebSite3AdminMenuManage.aspx.cs:28
       System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +122
       System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +792
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +738
       System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +88
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +114
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +159
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
    

    版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.17929




    2.解决办法


     public void InitPage()
        {
            menu_tbBll menuBll = new menu_tbBll();
            GvMenu.DataSource = menuBll.GetList();
            GvMenu.DataKeyNames = new string[] { "ID" };
            GvMenu.DataBind();
        }

     protected void GvMenu_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //Response.Write(MyClass.Alert(e.RowIndex.ToString()+"1111111"));
            string id = this.GvMenu.DataKeys[e.RowIndex].Value.ToString();
            string fatherID = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
            string thisTitle = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
            string thisUrl = ((TextBox)(GvMenu.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
            string sql_str = "update menu_tb set PID=" + fatherID + ", Title='" + thisTitle + "', Urls='" + thisUrl + "'";
            OleDbCommand sqlcom = new OleDbCommand();
            sqlcom.Connection = MyClass.Open();
            sqlcom.CommandText = sql_str;
            int i = sqlcom.ExecuteNonQuery();
            if (i > 0)
            {
                MyClass.Alert("更新成功");
            }
            else
            {
                MyClass.Alert("更新失败");
            }
            MyClass.Close();
            GvMenu.EditIndex = -1;
            this.InitPage();
        
        }

  • 相关阅读:
    几维安全SDK应用加固,全线5折为APP保驾护航
    物联网渗透测试威胁建模,捕捉应用相关安全风险
    【几维安全】Android代码混淆,代码混淆工具,Android版使用详细说明
    畅想物联网安全未来,几维安全让万物互联更安全
    域起网络携手几维安全,护航互联网游戏业务安全
    Android 加密, Android 常用加密, Android So 库高强度加密
    车联网安全威胁分析及防护思路,几维安全为智能汽车保驾护航
    C#实现基于ffmpeg加虹软的人脸识别
    OSX 下搭建Asp.Net vNext的开发环境
    验证码识别记录
  • 原文地址:https://www.cnblogs.com/shugen/p/6863041.html
Copyright © 2020-2023  润新知