在gridview的RowUpdate事件中获取列的值 [英] getting value of a column in RowUpdate event of gridview

查看:287
本文介绍了在gridview的RowUpdate事件中获取列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,我在gridview的一个非常基本的领域面临问题.我正在使用Gridview显示记录,然后为每一行提供编辑"选项.我没有在gridview中使用任何控件,直接有值.

现在,当用户在编辑模式下单击更新按钮时,不会从gridview的任何列中获取更新的值. Gridview的结构类似于:

Dear Friends, I''m facing problem in a very basic area of gridview. I''m using a Gridview to display records and then have Edit option for each row. I''m not using any control inside gridview, directly values are there.

Now, when user clicks update button in edit mode, not getting updated value from any columns of gridview. Gridview structure is like:

<asp:GridView ID="gvTime" runat="server" AutoGenerateEditButton="True" 
                    AutoGenerateColumns="True" CellPadding="1" CellSpacing="1" 
                    onrowcancelingedit="gvTime_RowCancelingEdit" onrowediting="gvTime_RowEditing" 
                    onrowupdating="gvTime_RowUpdating">
                    <RowStyle HorizontalAlign="Center" />
                    <HeaderStyle HorizontalAlign="Center" />
                    <EditRowStyle BackColor="#CCFFCC" ForeColor="Maroon" HorizontalAlign="Center" />
                </asp:GridView>


现在,在Rowupdating事件中,就像:


Now, in Rowupdating event, it''s like :

<pre lang="c#">
 protected void gvTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
int index = int.Parse(Session["Index"].ToString())+1;
GridViewRow row = gvTime.Rows[index];
string overtime = e.NewValues[0].ToString();
gvTime.EditIndex = -1;
BindData();



在这里,字符串超时总是显示旧数据,而永远无法提取用户输入的新数据.我想手动调用SQLCommand来基于上述函数中的更新值来更新数据库.请给我一些解决方案.



Here string overtime is always showing olddata, never can pull new data entered by user. I want to manually call SQLCommand to update database based on this updated value from the above function. Please give me some solution.

推荐答案

 protected void gvTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
int index = e.RowIndex;
GridViewRow row = gvTime.Rows[index];
//Call your update statement here!
UpdateData(ID); //Something like this
BindData();



希望对您有所帮助.



Hope it helps.


这篇关于在gridview的RowUpdate事件中获取列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆