| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 817 人关注过本帖
标题:求助!!
只看楼主 加入收藏
雪夜白狼
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2008-3-24
收藏
 问题点数:0 回复次数:4 
求助!!
gridview的编辑功能
 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        OleDbConnection conn;
        conn = DB.DBconntionadmin();
        conn.Open();

        string ID = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        //GridViewRow row = this.GridView1.Rows[e.RowIndex]; //定义更新行对象
       string username = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text;
        string userpwd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
        string popedom = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;



        //string sql3 = "update admin set username='" + ((TextBox)(row.Cells[0].Controls[0])).Text.ToString() + "' and userpwd='" + ((TextBox)(row.Cells[1].Controls[0])).Text.ToString() + "' and popedom='" + ((TextBox)(row.Cells[2].Controls[0])).Text.ToString() + "' where id=" + ID;
        string sql3 = "update admin set username='" + username + "' and userpwd='" + userpwd + "' and popedom='" + popedom + "' where id=" + ID;
        OleDbCommand com = new OleDbCommand(sql3, conn);
        com.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        conn.Close();
        getbinder();

在红色字体处报错
无法将类型为“System.Web.UI.WebControls.DataControlLinkButton”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。
搜索更多相关主题的帖子: 编辑 void 
2008-05-15 21:20
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]))
(GridView1.Rows[e.RowIndex].Cells[1].Controls[0]))
(GridView1.Rows[e.RowIndex].Cells[2].Controls[0]))
这三次找到的控件是LinkButton不是textbox……
看看你的textbox的位置到底在gridview的什么地方……
2008-05-16 10:05
kevintang
Rank: 4
等 级:业余侠客
威 望:9
帖 子:799
专家分:236
注 册:2008-2-14
收藏
得分:0 
2008-05-16 11:03
雪夜白狼
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2008-3-24
收藏
得分:0 
解决了啊
我加了几个textbox控件
2008-05-16 14:57
雪夜白狼
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2008-3-24
收藏
得分:0 
可是别的问题又来了啊!!
  string ID = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        //GridViewRow row = this.GridView1.Rows[e.RowIndex]; //定义更新行对象
        string username = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].FindControl("TextBox4")).Text;
        string userpwd = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("TextBox5")).Text;
        string popedom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("TextBox6")).Text;



string popedom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("TextBox6")).Text;

指定的参数已超出有效值的范围。
参数名: index
即便是能编辑的显示的也不是所填写的内容
显示不是0就是-1
是怎么回事呢?
2008-05-16 19:23
快速回复:求助!!
数据加载中...
 
   



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

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