| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 895 人关注过本帖
标题://GridView更新数据的时候,提示:指定的参数已超出有效值的范围
只看楼主 加入收藏
myjieli
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-12-9
结帖率:0
收藏
已结贴  问题点数:0 回复次数:1 
//GridView更新数据的时候,提示:指定的参数已超出有效值的范围
//后台更新语句   
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        sqlcon = new SqlConnection();
        string sqlstr = "update info set Name='" //指定的参数已超出有效值的范围。参数名: index。
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Sex='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "' where id='"
            + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        sqlcom = new SqlCommand(sqlstr, sqlcon);
        sqlcon.Open();
        sqlcom.ExecuteNonQuery();
        sqlcon.Close();
        GridView1.EditIndex = -1;
        bind();

    }
//前台语句
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            onrowcancelingedit="GridView1_RowCancelingEdit"
            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
            onrowupdating="GridView1_RowUpdating">
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="名字" />
                <asp:BoundField DataField="Sex" HeaderText="性别" />
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>
搜索更多相关主题的帖子: index 
2011-01-11 08:09
筱晓绾
Rank: 10Rank: 10Rank: 10
来 自:湖南
等 级:贵宾
威 望:12
帖 子:512
专家分:1736
注 册:2010-9-1
收藏
得分:20 
设个断点,调试GridView1.Rows[e.RowIndex].Cells[1].Controls[0]以及GridView1.Rows[e.RowIndex].Cells[2].Controls[0]还有GridView1.DataKeys[e.RowIndex].Value.ToString()的值,看是否是更新的内容.如果不是,则需要重新取值.
2011-01-11 08:33
快速回复://GridView更新数据的时候,提示:指定的参数已超出有效值的范围
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015902 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved