GridView更新操作问题

来源:互联网 发布:单片机应用技术 推荐 编辑:程序博客网 时间:2024/05/22 12:38
在RowUpdating的事件里,怎么样获取
<asp:BoundField> </asp:BoundField>
里的值???
 
方法1:
 
try   something   like

GridViewRow   row   =   GridView1.Rows[e.RowIndex];
if   (row   !=   null)
{
    TextBox   tb   =   row.Cells[n].Controls[0]   as   TextBox;   //change   n   to   the   position   of   your   bound   field
    if   (tb   !=   null)
    {
Response.Write(tb.Text);
    }
}

protected   void   GridView1_RowUpdating(object   sender,   GridViewUpdateEventArgs   e)
                {
                        try
                        {
                                GridViewRow   myrow   =   GridView1.Rows[e.RowIndex];
                                string   name   =   ((TextBox)myrow.Cells[1].Controls[0]).Text;
                                string   pwd   =   ((TextBox)myrow.Cells[2].Controls[0]).Text;

                                string   sql   =   "update   dc4_user_def   set   username= ' "   +   name   +   " ',password= ' "   +   pwd   +   " 'where   userid= ' "   +   userid   +   " ' ";
                                DBHelper.ExcuteQuery(sql);

                                GridView1.EditIndex   =   -1;
                                this.BindGridView();                                
                        }
                        catch   (Exception   ex)
                        {
                                Response.Write(ex.Message);
                        }
                }
原创粉丝点击