0

I have created grid dynamically and wanted to bind it.

I wanted to place grid in tabpanel.

I made following code for this purpose:

Protected Sub TabContainer1_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) 
    Handles TabContainer1.ActiveTabChanged
                Dim actTab As String = TabContainer1.ActiveTab.ID.ToString()
                Dim gv As GridView

                ds = gc.GetDataToListBinder("select * from ParameterOnline where TabName='Courts'")

                If actTab = "Panel_Courts" Then
                    gv.DataSource = ds.Tables(0)
                    TabContainer1.ActiveTab.Controls.Add(gv)
                End If


            End Sub

But its giving me error:

object not set to an instance of an object

By debugging i seen the dataset ds, but it is having all the necessary values in it.

I am not understanding where i am making mistake?

Answer in c# will also help me.

EDIT:

On gv.DataSource = ds.Tables(0) line i am getting error.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
C Sharper
  • 8,284
  • 26
  • 88
  • 151

2 Answers2

1

You are declaring the gridview but not instanstiating it. This article of creating gridview dynamically will helpful.

Change

Dim gv As GridView

To

Dim gv As GridView =  New GridView() 
Adil
  • 146,340
  • 25
  • 209
  • 204
1

useNew keyword to instantiate your gridview

change your code:

Dim gv As GridView

into this code:

Dim gv As New GridView()

Check out this Gridview constructor

Hope this will help you to over come this roadblock.