Gridview在运行时不可见

时间:2014-01-09 17:57:12

标签: asp.net vb.net gridview

Gridview在运行时不可见,我也没有设置可见属性。

有什么建议吗?

我的代码是:

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


  Dim sqlCnn As SqlConnection
        Dim sqlCmd As SqlCommand
        Dim sql As String
        Dim sda As SqlDataAdapter

        Dim connectionString As String = "Data Source=THERAIN\SQLEXPRESS;Initial Catalog=Ashok;User ID=sa;Password=Ashok"
        sqlCnn = New SqlConnection(connectionString)
        sql = "SELECT * FROM Income WHERE date>='" + TextBox1.Text.ToString + "' and date<='" + TextBox2.Text.ToString + "'"

        sda = New SqlDataAdapter(sql, sqlCnn)

        sqlCnn.Open()

        Dim ds As New DataSet

        Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(sda)

        sda.Fill(ds)
        GridView1.DataSource = ds.Tables("Income")
        sqlCnn.Close()
        GridView1.Visible = True
    End Sub

1 个答案:

答案 0 :(得分:2)

是的,做一个:

GridView1.DataBind()

设置数据源后。