>< asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging"> >< /asp:GridView>>To build the gridview I put the following in the Page_Load method
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) > If GridView1.Columns().Count = 0 Then > Dim strConn As String = "SERVER=myServer;USER ID=myId;PASSWORD=myPassword;DATABASE=myDB;" > Dim objConn As New MySqlConnection(strConn) > Dim strSql As String > > Dim objGvDS As New DataSet > > strSql = "select * from myTable" > Dim daParms As New MySqlDataAdapter(strSql, objConn) > daParms.Fill(objGvDS, "dtParms") > > Dim myCol1 As New BoundField > myCol1.HeaderText = "FirstHeader" > myCol1.DataField = "FirstField" > GridView1.Columns.Add(myCol1) > > Dim myCol2 As New BoundField > myCol2.HeaderText = "SecondHeader" > myCol2.DataField = "SecondField" > GridView1.Columns.Add(myCol2) > > GridView1.DataSource = objGvDS > GridView1.DataBind() > > objConn.Close() > objConn.Dispose() > End If > > End Sub > > Protected Sub GridView1_PageIndexChanging(ByVal sender As Object,_ > ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) > sender.pageindex = e.NewPageIndex > End Sub>
If GridView1.Columns().Count = 0 Thenwas because each time the Page_Load method fired, it would add two columns to the gridview.