none
gridview查询结果编辑问题 RRS feed

  • 问题

  • gridview查询的结果在编辑时,会把整张表全显示出来,并且会将表的第一行设为编辑状态。查资料后说是应该在page_load里做

    个判断,但毫无头绪,请求帮助,谢谢

    这是page_load部分代码:

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Bind()
            End If
        End Sub
        Private Sub Bind()
            Dim connectionString As String = WebConfigurationManager.ConnectionStrings("Sandb").ConnectionString
            Dim con As New MySqlConnection(connectionString)
            Dim sqlStr As String = "SELECT * FROM hr"
            Dim cmd As New MySqlCommand(sqlStr, con)
            Dim da As New MySqlDataAdapter(cmd)
            Dim ds As New DataSet()
            con.Open()
            da.Fill(ds, "hr")
            GridView1.DataSource = ds
            GridView1.DataKeyNames = New String() {"id"}
            GridView1.DataBind()
            con.Close()

        End Sub


    2015年3月26日 4:03

答案