源错误: 
行 19:     {
行 20:         int id = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][0]);
行 21:         string Title =Convert.ToString (GVContype.DataKeys[GVContype.EditIndex][1]);
行 22:         int type = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][2]);
行 23:         string intro = ((TextBox)this.GVContype.DataKeys[GVContype.EditIndex][3]).ToString();
 源文件: e:\工作\Web\ComContentType.aspx.cs    行: 21 
网上找了很多办法都不行 到底要怎么弄啊~~在线等

解决方案 »

  1.   

    DataKeys是这么用的吗??
    你就说你要干什么吧??然后把你的前台代码贴出来看下!~·
      

  2.   

    我就想去在gridview做修改
             int id = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][0]);
            string Title =Convert.ToString (GVContype.DataKeys[GVContype.EditIndex][1]);
            int type = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][2]);
            string intro = ((TextBox)this.GVContype.DataKeys[GVContype.EditIndex][3]).ToString();
            int hits = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][4]);
            DateTime checkintime = Convert.ToDateTime((TextBox)this.GVContype.DataKeys[GVContype.EditIndex][5]);
            int sortid = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][6]);
            int staue = Convert.ToInt32(GVContype.DataKeys[GVContype.EditIndex][7]); ComContentType_BC.update_Contenttype(id, Title, type, intro, hits, checkintime, sortid, staue);
      

  3.   

    ??
    把前台代码拿出来看看!~~
    然后你这个GridView你要怎么修改??
      

  4.   

    <asp:GridView ID="GVContype" runat="server" AutoGenerateColumns="False" DataKeyNames="ComContentTypeID"
                DataSourceID="SqlDataSource2" OnRowUpdating="GVContype_RowUpdating" Width="1096px">
                <Columns>
                    <asp:BoundField DataField="ComContentTypeID" HeaderText="ComContentTypeID" InsertVisible="False"
                        ReadOnly="True" SortExpression="ComContentTypeID" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                    <asp:BoundField DataField="Intro" HeaderText="Intro" SortExpression="Intro" />
                    <asp:BoundField DataField="Hits" HeaderText="Hits" SortExpression="Hits" />
                    <asp:BoundField DataField="CheckInTime" HeaderText="CheckInTime" SortExpression="CheckInTime" />
                    <asp:BoundField DataField="SortID" HeaderText="SortID" SortExpression="SortID" />
                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
                    <asp:CommandField ShowEditButton="True" />
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:19ding_cnConnectionString4 %>"
                SelectCommand="SELECT * FROM [ComContentType]"></asp:SqlDataSource>直接在列表里点修改,可以对数据进行操作。
      

  5.   

    数据库中有几个主键 设置下DatakeysName
      

  6.   

    就一个 我已经设置了,如何取gridview里剩下的值?
      

  7.   

    string Title = GVContype.Rows[GVContype.EditIndex].Cells[1].Text;其余的自己改吧 
      

  8.   

            protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            string Title = ((TextBox)(GVContype.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
            int type = Convert.ToInt32(((TextBox)(GVContype.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim());
            string intro = ((TextBox)(GVContype.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
            int hits = Convert.ToInt32(((TextBox)(GVContype.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim());
            //后略,照着前面的写
            ComContentType_BC.update_Contenttype(id, Title, type, intro, hits, checkintime, sortid, staue); 
            GridView1.EditIndex = -1;
            bind();   //数据绑定函数
        }    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            bind();
        }    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            bind();
        }    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sqlStr = "delete from Employee where ID=" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value) + "";
            Common.ExecuteSql(sqlStr);
            bind();
        }
      

  9.   

    int hits = Convert.ToInt32(((TextBox)(GVContype.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim()); 这样取到的值为什么点 更新以后取到的还是原来的值呢?
      

  10.   

    呀!~~
    这就要看你更新后有没有成功的写如数据库了。。
    写入数据库成功后又要看你有没有对这个GridView进行再次绑定了!~~
      

  11.   

    索引超出范围  就是你如果数组只有3个的话 array[0],array[1],array[2]都是合法的,array[3]就超出范围了。