Dynamically creating a GridView inside AjaxControlToolkit Tabs

04 Jun

I wanted to search through multiple tables in database and display the results in GridViews inside Ajax Tabs, each tab will represent the results of a single table


First I need to a add an AjaxControlToolkit Tab Container


<cc2:TabContainer  AutoPostBack=”false”  ID=”TabContainer1″ runat=”server” Width=”100%”></cc2:TabContainer>


In my Code I will create a function to create the result tab, the input of this function is a DataSet of the search results through a single table and the Table name


    Private Sub fillDGResults(ByVal ds As DataSet, ByVal sTableName As String )

         Dim tab As AjaxControlToolkit.TabPanel = New AjaxControlToolkit.TabPanel()

         tab.ID = “tab_” + sTableName  

         tab.Style.Item(“Width”) = “100%”


         Dim UpPanel As UpdatePanel = New UpdatePanel()

         Dim printButton As ImageButton = New ImageButton()

         printButton.ImageUrl = “images/print1_norm.PNG”

         UpPanel.UpdateMode = UpdatePanelUpdateMode.Conditional


         Dim gv As GridView = New GridView

         gv = CreateGridView()

         gv.ID = sTableName + ds.Tables(0).Rows.Count.ToString()

         printButton.Attributes(“onClick”) = “javascript:CallPrint(‘” & gv.ID & “‘,'” & sTableName & “‘);”

         UpPanel.ID = “up_” + sTableName




         gv.Style.Item(“Width”) = “100%”

         gv.DataSource = ds

         gv.PageIndex = 0


         gv.PageIndex = 0

         tab.HeaderText = sTableName + ” (“ + ds.Tables(0).Rows.Count.ToString() + “)”

         tab.EnableViewState = True

         TabContainer1.EnableViewState = True

     End Sub



And this is the function to create the GridView



   Private Function CreateGridView() As GridView

        Dim gv As GridView = New GridView()

        AddHandler gv.RowDataBound, AddressOf gv_RowDataBound

        AddHandler gv.RowCreated, AddressOf gv_RowCreated

        AddHandler gv.RowEditing, AddressOf gv_RowEditing

        AddHandler gv.SelectedIndexChanged, AddressOf gv_SelectedIndexChanged

        AddHandler gv.RowCommand, AddressOf gv_RowCommand

        AddHandler gv.PageIndexChanging, AddressOf gv_PageIndexChanging

        AddHandler gv.PageIndexChanged, AddressOf gv_PageIndexChanged


        gv.PageIndex = 0

        gv.EnableViewState = True

        gv.FooterStyle.CssClass = “SimpleGrayTableFooterStyle”

        gv.RowStyle.CssClass = “ResultsPanel”

        gv.HeaderStyle.CssClass = “ResultsPanelHeader”

        gv.PagerStyle.CssClass = “PagerStyle”

        gv.AllowPaging = True

        gv.PageSize = 15

        gv.PagerSettings.Mode = PagerButtons.NumericFirstLast

        gv.PagerSettings.Position = PagerPosition.TopAndBottom

        gv.PagerSettings.FirstPageText = “<<“

        gv.PagerSettings.LastPageText = “>>”

        gv.PagerSettings.PageButtonCount = 5


        Dim aspCF As CommandField = New CommandField()

        aspCF.ShowSelectButton = True

        aspCF.ButtonType = ButtonType.Link

        aspCF.SelectText = “<img align=top BorderColor=transparent border=0 alt=’Show in Map’ src=’images/map20_norm.PNG’ />”


        aspCF = New CommandField()

        aspCF.ShowEditButton = True

        aspCF.EditText = “<img align=top BorderColor=transparent border=0 alt=’Show Info’ src=’images/view_norm.PNG’ />”



        gv.Page = Me.Page

        CreateGridView = gv


    End Function



Finally I would like to thank Siderite for his help


1 Comment

Posted by on June 4, 2008 in General, Programming


Tags: , , , , ,

One response to “Dynamically creating a GridView inside AjaxControlToolkit Tabs

  1. Ted Chapin

    May 6, 2009 at 6:48 pm

    How did you avoid getting the error:
    Specified argument was out of the range of valid values


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: