none
GridView的updating事件中的e.NewValues["EName"].toString();取不到值

    问题

  • 在使用GridView过程中,前前后后遇到过好几次这样诡异的情况,e.NewValues无论如何都为空,用数据源控件就没有问题,我自己给他DataSet则不行。
    代码如下,希望朋友慧眼指正一下

     

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" 
    
       DataKeyNames="EID"
    
       onrowupdating="GridView1_RowUpdating" onrowediting="GridView1_RowEditing">
    
       <Columns>
    
        <asp:BoundField DataField="EName" HeaderText="EName" SortExpression="EName" />
    
        <asp:BoundField DataField="EJob" HeaderText="EJob" SortExpression="EJob" />
    
        <asp:BoundField DataField="Etel" HeaderText="Etel" SortExpression="Etel" />
    
        <asp:BoundField DataField="EFax" HeaderText="EFax" SortExpression="EFax" />
    
        <asp:BoundField DataField="EEmail" HeaderText="EEmail" 
    
         SortExpression="EEmail" />
    
        <asp:BoundField DataField="EDate" HeaderText="EDate" SortExpression="EDate" />
    
       </Columns>
    
      </asp:GridView>
    
    

     

    using System;
    
    using System.Collections.Generic;
    
    using System.Web;
    
    using System.Web.UI;
    
    using System.Web.UI.WebControls;
    
    
    
    public partial class admin_Default : System.Web.UI.Page
    
    {
    
     protected void Page_Load(object sender, EventArgs e)
    
     {
    
       DataBound();
    
     }
    
     private void DataBound()
    
     {
    
      System.Data.DataSet ds = Socut.Data.ExecuteDataSet("select * from employetb","bb");
    
      this.GridView1.DataSource = ds;
    
      this.GridView1.DataBind();
    
     }
    
     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    
     {
    
      string str = e.NewValues["EName"].ToString();//在这里一直取不到值,说是为空
    
     }
    
     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    
     {
    
      this.GridView1.EditIndex = e.NewEditIndex;
    
      DataBound();
    
     }
    
    }
    
    
    2010年7月2日 8:10

答案

全部回复