| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1166 人关注过本帖
标题:【已解决】GridView自带编辑无法取得修改后的数据
只看楼主 加入收藏
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
结帖率:0
收藏
 问题点数:0 回复次数:1 
【已解决】GridView自带编辑无法取得修改后的数据
        <asp:GridView ID="ArticleList" runat="server" CellPadding="4"
            ForeColor="Black" GridLines="Vertical" Width="100%" AutoGenerateColumns="False"
            onrowcancelingedit="ArticleList_RowCancelingEdit"
            onrowdeleting="ArticleList_RowDeleting" onrowediting="ArticleList_RowEditing"
            onrowupdating="ArticleList_RowUpdating" BackColor="White"
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
            DataKeyNames="CustomerID">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <Columns>
                <asp:BoundField DataField="CustomerName" HeaderText="用户姓名" />
                <asp:BoundField DataField="CustomerSex" HeaderText="用户性别" />
                <asp:BoundField DataField="Address" HeaderText="家庭住址" />
                <asp:BoundField DataField="CustomerTel" HeaderText="联系电话" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>


    protected void ArticleList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string CustomerID = this.ArticleList.DataKeys[e.RowIndex][0].ToString();
        string CustomerName = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim();
        string CustomerSex = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string Address = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
        string CustomerTel = ((TextBox)(this.ArticleList.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
        UpdateCus(CustomerID, CustomerName, CustomerSex, CustomerTel, Address);
        this.ArticleList.EditIndex = -1;
        getlist();
    }


    public void UpdateCus(string CustomerID, string CustomerName, string CustomerSex, string CustomerTel, string Address)
    {
        try
        {
            OpenConnection();
             = CommandType.Text;
             = "Update [Customer] Set CustomerName = '" + CustomerName + "', CustomerSex = " + CustomerSex + ", CustomerTel = '" + CustomerTel + "', Address = '" + Address + "' where CustomerID = " + CustomerID + "";
            comm.ExecuteNonQuery();
        }
        catch (Exception x)
        {
            Response.Write(x.Message);
        }
        finally
        {
            CloseConnection();
        }
    }


CustomerName, CustomerSex, CustomerTel, Address都取得是输出数据,而无法取得编辑表单中的数据是什么原因呢?

[ 本帖最后由 zhangyao3287 于 2010-1-20 13:51 编辑 ]
搜索更多相关主题的帖子: GridView 数据 
2010-01-20 11:36
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:0 
又是IsPostBack惹得祸
2010-01-20 13:50
快速回复:【已解决】GridView自带编辑无法取得修改后的数据
数据加载中...
 
   



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

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