在RowUpdating的事件里,怎么样获取
<asp:BoundField></asp:BoundField>
里的值???

解决方案 »

  1.   

    try something likeGridViewRow 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);
      }
    }
      

  2.   

    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);
                }
            }
      

  3.   

    点击编辑后,我更新里面的内容
    然后点击更新,可是就是更新不了更新按钮的代码
     protected void GVeditor_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
          try
            {
                string cj = ((TextBox)e.NewValues[5]).Text
                string kccj = ((TextBox)e.NewValues[6]).Text).Text;
                string xk = ((TextBox)e.NewValues[1]).Text;
                string km = ((TextBox)e.NewValues[4]).Text;            string cmdtext = "update 成绩 set 成绩='" + cj + "',考查成绩='" + kccj + "' where 成绩.学生='" + xk + "' and 成绩.科目 in (select ID from 科目 where 科目.科目='" + km + "')";
                SqlConnection sqlconn = new SqlConnection(sqllink.sqlconn());
                sqlconn.Open();            SqlCommand sqlcomm = new SqlCommand(cmdtext, sqlconn);
                sqlcomm.ExecuteNonQuery();
                sqlconn.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            this.GVeditor.DataSource = gvBind();
            this.GVeditor.DataBind();   
            GVeditor.EditIndex = -1;
            
    //////////////////HTML代码
       <asp:GridView ID="GVeditor" runat="server" Width="100%" Height="72px" AutoGenerateColumns="False" OnRowCancelingEdit="GVeditor_RowCancelingEdit" OnRowEditing="GVeditor_RowEditing" OnRowUpdating="GVeditor_RowUpdating" OnRowUpdated="GVeditor_RowUpdated" >
                    <Columns>
                        <asp:BoundField DataField="学号" HeaderText="学号" ReadOnly="True" />
                        <asp:BoundField DataField="班级" HeaderText="班级" ReadOnly="True" />
                        <asp:BoundField DataField="姓名" HeaderText="姓名" ReadOnly="True" />
                        <asp:BoundField DataField="科目" HeaderText="科目" ReadOnly="True" />
                        <asp:TemplateField HeaderText="成绩">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("成绩") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%#Eval("成绩") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="考查成绩">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" Text='<%#Eval("考查成绩")%>'  runat="server"></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%#Eval("考查成绩") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True"></asp:CommandField>      
                    </Columns>
               </asp:GridView>