datagrid中设置了读取了数据库的数据,之后在网页中点编辑,之后在文本框中输入需要的值,但是点更新后,数据还是那个,没变
代码如下
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        SqlDataAdapter1.Fill(DataSet1, "读者")
        DataGrid1.DataSource = DataSet1.Tables(0).DefaultView
        DataGrid1.DataBind()
    End Sub
-------
    Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
        Dim tx As TextBox
        Dim r As DataRow
        r = DataSet1.Tables(0).Rows(e.Item.ItemIndex)        tx = CType(e.Item.Cells(2).Controls(0), TextBox)
        r.Item(0) = tx.Text
        tx = CType(e.Item.Cells(3).Controls(0), TextBox)
        r.Item(1) = tx.Text
        tx = CType(e.Item.Cells(4).Controls(0), TextBox)
        r.Item(2) = tx.Text
        tx = CType(e.Item.Cells(5).Controls(0), TextBox)
        r.Item(3) = tx.Text
        tx = CType(e.Item.Cells(6).Controls(0), TextBox)
        r.Item(4) = tx.Text
        tx = CType(e.Item.Cells(7).Controls(0), TextBox)
        r.Item(5) = CType(tx.Text, Date)        SqlDataAdapter1.Update(DataSet1, "读者")
        DataGrid1.EditItemIndex = -1
        DataGrid1.DataBind()
    End Sub

解决方案 »

  1.   

    而且问题出在
    即使输入了修改的信息,tx.text也还保留着原来的值,无法把值传送给 r.Item(0)
      

  2.   

    DataGrid1.DataBind()改为:DataGrid1.DataSource = DataSet;
    DataGrid1.DataBind()
      

  3.   

    DataGrid1.DataBind()改为:DataGrid1.DataSource = DataSet1;
    DataGrid1.DataBind()
      

  4.   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            if not page.postback then
            SqlDataAdapter1.Fill(DataSet1, "读者")
            DataGrid1.DataSource = DataSet1.Tables(0).DefaultView
            DataGrid1.DataBind()
            end if
        End Sub
    反正就是pageload里数据绑定的问题
    在你的页点更新按钮的时候,页面刷新并同时执行一遍pageload,此时Datagrid内的数据会被重新绑定,原编辑状态会被冲掉
      

  5.   

    如果这样加上
    if not page.postback then
    end if
    点编辑后,就什么都看不到了,因为pageload里的数据邦定不执行了……怎么样能在重新pageload冲掉原数据前能备份出文本框中的数据呢?
      

  6.   

    我记得有个viewstate能保存发送前的数据,如何使用呢?