Hi,
I am Dynamically creating columns in the DataGrid at Page_Load(). When Click on "Next" or "Previous" pager, it does not trigger the dgdoclist_PageIndexChanged() Event or atleast it does not execute the Sub definded for "OnPageIndexChanged="dgdoclist_PageIndexChange d".
I am attaching the CodeBehind File and Web Page code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Check if user is aready looged in
If Session("SESS_Logged_On") <> True Then
Session("urlRequest") = Request.Url.PathAndQuery
Response.Redirect("Login.aspx")
End If
If Session("DocSearch") = "" Then
Response.Redirect("DocLibSearch.aspx")
End If
If Not Page.IsPostBack Then
If Session("StyleSheet") Is Nothing Or Session("StyleSheet") <> "" Then
Dim objStyle As New HSIComponents.HSIStore
Session("StyleSheet") = objStyle.GetStyleSheet(Session("D_CompID"), Session("D_BusUnit"))
Session("ImageDir") = objStyle.GetImageDir(Session("D_CompID"), Session("D_BusUnit"))
End If
Session("DocsList") = Nothing
Else
End If
If Request("MenuID") <> "" Then
Session("Menu") = Request("MenuID")
End If
Session("SESS_SelDocValue") = Request.Form("ddDocList")
'Populate Menu Panel
Call Populate_MenuPanel()
'Populate Data Grid
Call Populate_DataGrid()
End Sub
Private Sub Populate_MenuPanel()
Dim objMenu As New HSIMenus.Menus
Dim tblTbl As New Table
Dim ddDoc As New DropDownList
' Add the Menu Control to the Left Panel
tblTbl = objMenu.BuildMenus(Session("D_CompID"), Session("D_BusUnit"), Session("Menu"), Session("SESS_userid"), Request.ServerVariables("SCRIPT_NAME"))
leftpanel.Controls.Add(tblTbl)
' Add two <BR>s to the Panel
Dim strBR1 As New Literal
strBR1.ID = "br1"
strBR1.Text = "<BR>"
' leftpanel.Controls.Add(strBR1)
' Add the Label Control to the Left Panel
Dim lblCntr1 As New Label
lblCntr1.ID = "lblCntr1"
lblCntr1.Text = "<BR><BR>Document Types<BR>"
lblCntr1.CssClass = "searchtype"
' Add the Label Control to the Left Panel
leftpanel.Controls.Add(lblCntr1)
' Add the DropDown Control to the Left Panel
ddDoc = objMenu.BuildDocList(Session("D_CompID"), Session("D_BusUnit"), Session("SESS_userid"))
leftpanel.Controls.Add(ddDoc)
' Add the Label Control to the Left Panel
Dim lblCntr2 As New Label
lblCntr2.ID = "lblCntr2"
lblCntr2.Text = "<BR><BR>Display<BR>"
lblCntr2.CssClass = "searchtype"
leftpanel.Controls.Add(lblCntr2)
' Add the DropDown List Control for No Of Records to be displayed on the page
Dim ddCntr As New DropDownList
Dim elements1() As String = New String() {"20 Item(s) Per Page", "30 Item(s) Per Page", "40 Item(s) Per Page", "50 Item(s) Per Page", "100 Item(s) Per Page"}
Dim elements2() As String = New String() {"20", "30", "40", "50", "100"}
Dim i As Integer
For i = 0 To UBound(elements1)
Dim ddListItem As New ListItem
ddListItem.Text = elements1(i)
ddListItem.Value = elements2(i)
ddCntr.CssClass = "searchtype"
ddCntr.Items.Add(ddListItem)
Next
ddCntr.ID = "ddCntr"
ddCntr.AutoPostBack = True
leftpanel.Controls.Add(ddCntr)
End Sub
Public Sub Populate_DataGrid()
Dim objDataSet As New DataSet
Dim objDataView As New DataView
Dim ddCntr As New DropDownList
' Display predefined number of rows at the screen
With dgdoclist
If Not IsPostBack Then
.PageSize = 20
Else
If Val(Request.Form("ddCntr")) <> dgdoclist.PageSize Then
Dim intCurrPageSize As Integer = dgdoclist.PageSize
Dim intCurrPage As Integer = dgdoclist.CurrentPageIndex
Dim intCurrPos As Integer = (dgdoclist.CurrentPageIndex * dgdoclist.PageSize) + 1
Dim intNewPos = Int(intCurrPos / Val(Request.Form("ddCntr")))
Dim intRemain = intCurrPos Mod Val(Request.Form("ddCntr"))
If intRemain > 0 Then intNewPos = intNewPos + 1
If intNewPos - 1 < 0 Then
intNewPos = 0
Else
intNewPos = intNewPos - 1
End If
.PageSize = Val(Request.Form("ddCntr"))
.CurrentPageIndex = intNewPos
End If
End If
End With
If Not Session("DocsList") Is Nothing Then
' Retrieve the Data Set from the Session Object
objDataSet = CType(Session("DocsList"), DataSet)
objDataView = CType(Session("DocsListView"), DataView)
Else
' Bring in the datasets from the function
Dim objDocsList As New HSIComponents.HSIStore
' objDataSet = objDocsList.GetDocsList(Session("D_UserID"), " ")
objDataSet = objDocsList.GetSearchResults(Session("D_UserID"), _
Session("D_CompID"), _
Session("D_BusUnit"), _
Session("txtjdebill"), _
Session("txtjdeship"), _
Session("txtdocno"), _
Session("txtfdate"), _
Session("txttdate"), _
Session("txtcustsearch"), _
Session("txtitemsearch"), _
dgdoclist.CurrentPageIndex, _
dgdoclist.PageSize)
objDataView = objDataSet.Tables("DocsList").DefaultView
Session("DocsList") = objDataSet
Session("DocsListView") = objDataView
End If
If objDataSet.Tables("DocsList").Rows.Count > 0 Then
' Adding an additional hyperlink column to select the record to edit
Dim colHyperLink As New HyperLinkColumn
colHyperLink.HeaderText = "Document Reference"
colHyperLink.HeaderStyle.CssClass = "dgheader"
colHyperLink.DataNavigateUrlField = "RDDCLK"
colHyperLink.DataTextField = "RDDCNO"
colHyperLink.DataNavigateUrlFormatString = "javascript
:window.open('viewdoc.aspx?Edit=true&id ={0}','_blank','titlebar=no, resizable=yes, toolbar=no,location=no,directories=no, status=no, menubar=no, scrollbars=yes,width=650,height=400');void('');"
colHyperLink.SortExpression = "RDDCNO"
dgdoclist.Columns.Add(colHyperLink)
End If
' Bind rest of the data to the Data Grid
Dim cols As DataColumnCollection
Dim objRow As DataRow
' Use a DataTable object's DataColumnCollection.
cols = objDataSet.Tables("DocsList").Columns
If objDataSet.Tables("DocsList").Rows.Count > 0 Then
objRow = objDataSet.Tables("DocsList").Rows(0)
End If
' Set the ColumnName and values
Dim col As DataColumn
For Each col In cols
If objDataSet.Tables("DocsList").Rows.Count > 0 Then
If col.ColumnName <> dgdoclist.Columns(0).HeaderText Then
Dim colBounded As New BoundColumn
colBounded.HeaderText = col.ColumnName
colBounded.DataField = col.ColumnName
colBounded.HeaderStyle.CssClass = "dgheader"
colBounded.ItemStyle.Wrap = False
colBounded.SortExpression = col.ColumnName
dgdoclist.Columns.Add(colBounded)
End If
Else
Dim colBounded As New BoundColumn
colBounded.HeaderText = col.ColumnName
colBounded.DataField = col.ColumnName
colBounded.HeaderStyle.CssClass = "dgheader"
colBounded.ItemStyle.Wrap = False
colBounded.SortExpression = col.ColumnName
dgdoclist.Columns.Add(colBounded)
End If
Next
dgdoclist.DataSource = objDataView
dgdoclist.VirtualItemCount = 4000
dgdoclist.DataBind()
End Sub
Public Sub dgdoclist_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles dgdoclist.PageIndexChanged
' Set the Current Page to be displayed
dgdoclist.CurrentPageIndex = e.NewPageIndex
' Create a DataView from the DataTable, or Session Object
Dim objDocsList As New HSIComponents.HSIStore
Dim objDataSet As New DataSet
Dim objDataView As New DataView
' Bring in the new dataset
objDataSet = objDocsList.GetSearchResults(Session("D_UserID"), _
Session("D_CompID"), _
Session("D_BusUnit"), _
Session("txtjdebill"), _
Session("txtjdeship"), _
Session("txtdocno"), _
Session("txtfdate"), _
Session("txttdate"), _
Session("txtcustsearch"), _
Session("txtitemsearch"), _
dgdoclist.CurrentPageIndex, _
dgdoclist.PageSize)
objDataView = objDataSet.Tables("DocsList").DefaultView
Session("DocsList") = objDataSet
Session("DocsListView") = objDataView
' Bind the Data
dgdoclist.DataBind()
End Sub
Public Sub dgdoclist_Sort_Grid(ByVal source As Object, ByVal e As DataGridSortCommandEventArgs) Handles dgdoclist.SortCommand
' Retrieve the data source from session state.
' Create a DataView from the DataTable, or Session Object
Dim objDataView As New DataView
' Check if the datavoew exists in Session Object
If Not Session("DocsList") Is Nothing Then
' Retrieve the Data Set from the Session Object
objDataView = CType(Session("DocsListView"), DataView)
Else
' Bring in the datasets from the function
Dim objDocsList As New HSIComponents.HSIStore
Dim objDataSet As New DataSet
objDataSet = objDocsList.GetSearchResults(Session("D_UserID"), _
Session("D_CompID"), _
Session("D_BusUnit"), _
Session("txtjdebill"), _
Session("txtjdeship"), _
Session("txtdocno"), _
Session("txtfdate"), _
Session("txttdate"), _
Session("txtcustsearch"), _
Session("txtitemsearch"), _
dgdoclist.CurrentPageIndex, _
dgdoclist.PageSize)
objDataView = objDataSet.Tables("DocsList").DefaultView
Session("DocsList") = objDataSet
Session("DocsListView") = objDataView
End If
' The DataView provides an easy way to sort. Simply set the
' Sort property with the name of the field to sort by.
objDataView.Sort = e.SortExpression
Session("DocsListView") = objDataView
' Rebind the data source and specify that it should be sorted
' by the field specified in the SortExpression property.
dgdoclist.DataSource = objDataView
dgdoclist.DataBind()
End Sub
HTML===============
<%@ Register TagPrefix="ImgArc" TagName="Style" Src="Style.ascx"%>
<%@ Register TagPrefix="ImgArc" TagName="Header" Src="header.ascx"%>
<%@ Page Language="
vb" Codebehind="doclib.aspx.
vb" AutoEventWireup="false" Inherits="ImageArch.doclib"%>
<HTML>
<HEAD>
<title>Document Library</title>
<IMGARC:STYLE id="mystyle" runat="server"></IMGARC:STYLE><IMGARC:HEADER id="header" runat="server"></IMGARC:HEADER>
<STYLE>A:link { COLOR: #00008b; TEXT-DECORATION: none }
A:visited { COLOR: #00008b; TEXT-DECORATION: none }
A:active { COLOR: #ff0000; TEXT-DECORATION: underline }
A:hover { COLOR: #ff0000; TEXT-DECORATION: underline }
</STYLE>
</HEAD>
<body>
<form id="doclib" name="doclib" runat="server">
<asp:table id="Table1" Runat="server" Width="689" height="418">
<asp:tablerow Runat="server" ID="Tablerow1">
<asp:tablecell VerticalAlign="Top" cssclass="headerbg" runat="server" ID="Tablecell1" Width="152px">
<asp:Panel ID="leftpanel" Runat="server" CssClass="headerbg" Width="152px" Height="412px">
<asp:Table id="tblsearch" Width="152px" Runat="server" CellPadding="2" CellSpacing="0">
<asp:TableRow>
<asp:TableCell CssClass="tblrow" Runat="server" ID="Tablecell2">Search</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tblcell" Runat="server" ID="Tablecell3">Enter Keyword(s)<br>
<asp:TextBox id="txtsearch" Runat="server" CssClass="body" MaxLength="50"></asp:TextBox><br>
<asp:Button id="submitsearch" cssClass="body" Runat="server" Text="Submit Query"></asp:Button><br>
<asp:HyperLink ID="useradvsearch" runat="server" NavigateUrl="useradvsearch.aspx">Advance Search</asp:HyperLink>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<BR>
<BR>
</asp:Panel>
</asp:tablecell>
<asp:tablecell VerticalAlign="Top" CssClass="headerbg" runat="server" ID="Tablecell5">
<asp:DataGrid id="dgdoclist" runat="server" AllowCustomPaging="true" AllowPaging="true"
OnSortCommand="dgdoclist_Sort_Grid"
OnPageIndexChanged="dgdoclist_PageIndexChanged" EnableViewState="True"
AllowSorting="true" BackColor="#999999" BorderColor="#cccccc" BorderStyle="Outset" BorderWidth="1"
AutoGenerateColumns="false" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" AlternatingItemStyle-Wrap="false"
SelectedItemStyle-Wrap="false" FooterStyle-Wrap="false" PagerStyle-Wrap="false" EditItemStyle-Wrap="false"
HeaderStyle-CssClass="dgheader" ItemStyle-CssClass="dgitem" AlternatingItemStyle-CssClass="dgaltitem"
FooterStyle-CssClass="dgfooter" PagerStyle-CssClass="dgpager" PagerStyle-Mode="NextPrev" PagerStyle-NextPageText="Next Page"
PagerStyle-PrevPageText="Previous Page" PagerStyle-Position="TopAndBottom"></asp:DataGrid>
<br>
<br>
<a href="javascript
:window.open('adddoc.aspx?insert=t rue','_blank','titlebar=no, resizable=no, toolbar=no,location=no,directories=no, status=no, menubar=no, scrollbars=no');void('');"
class="links">Add Reference</a> <a href="javascript
:window.location.reload();void('') ;" class="links">
Refresh</a>
</asp:tablecell>
</asp:tablerow>
</asp:table>
</form>
</body>
</HTML>