S
Sudhir
I have created a dynamic datagrid and would like to sort
the grid when I click the column name in the header.
-----------------------------------------------
Private Sub btnSearch_Click(ByVal sender As
System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
BindGrid("")
End Sub
Private Sub BindGrid(ByVal Sortfield As String)
Dim strwhere1 As String = txtSrchform1.Text
Dim strwhere2 As String = txtSrchform2.Text
Dim Pid As Integer = CInt(Request.Cookies
("PageID").Value)
Dim dview As DataView
Dim ds As DataSet
ds = searchresults(Pid, "%" & strwhere1 & "%", "%"
& strwhere2 & "%", "")
dview = ds.Tables("Codes").DefaultView
dview.Sort = Sortfield
Dim path As String = PagePath(Pid)
Response.Write(path)
dg1.ID = "SrchResults"
dg1.AutoGenerateColumns = True
dg1.AllowSorting = True
dg1.DataSource = dview
dg1.DataKeyField = ds.Tables("Codes").Columns
(0).ColumnName
Dim hc1 As New HyperLinkColumn()
hc1.Text = "Select"
hc1.DataNavigateUrlField = ds.Tables
("Codes").Columns(0).ColumnName
hc1.DataNavigateUrlFormatString = path & "?ID={0}"
dg1.Columns.Add(hc1)
GridPlaceHolder.Controls.Add(dg1)
AddHandler dg1.ItemDataBound, AddressOf Hide_Column
AddHandler dg1.SortCommand, AddressOf
dg1_SortCommand
dg1.DataBind()
End Sub
Sub dg1_SortCommand(ByVal source As Object, ByVal e As
DataGridSortCommandEventArgs)
BindGrid(e.SortExpression)
End Sub
---------------------------------------------------
When I click the column name on the header, the grid
disappears. I do not understand where I have gone wrong.
Any help is appreciated.
Thanks,
Sudhir.
the grid when I click the column name in the header.
-----------------------------------------------
Private Sub btnSearch_Click(ByVal sender As
System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
BindGrid("")
End Sub
Private Sub BindGrid(ByVal Sortfield As String)
Dim strwhere1 As String = txtSrchform1.Text
Dim strwhere2 As String = txtSrchform2.Text
Dim Pid As Integer = CInt(Request.Cookies
("PageID").Value)
Dim dview As DataView
Dim ds As DataSet
ds = searchresults(Pid, "%" & strwhere1 & "%", "%"
& strwhere2 & "%", "")
dview = ds.Tables("Codes").DefaultView
dview.Sort = Sortfield
Dim path As String = PagePath(Pid)
Response.Write(path)
dg1.ID = "SrchResults"
dg1.AutoGenerateColumns = True
dg1.AllowSorting = True
dg1.DataSource = dview
dg1.DataKeyField = ds.Tables("Codes").Columns
(0).ColumnName
Dim hc1 As New HyperLinkColumn()
hc1.Text = "Select"
hc1.DataNavigateUrlField = ds.Tables
("Codes").Columns(0).ColumnName
hc1.DataNavigateUrlFormatString = path & "?ID={0}"
dg1.Columns.Add(hc1)
GridPlaceHolder.Controls.Add(dg1)
AddHandler dg1.ItemDataBound, AddressOf Hide_Column
AddHandler dg1.SortCommand, AddressOf
dg1_SortCommand
dg1.DataBind()
End Sub
Sub dg1_SortCommand(ByVal source As Object, ByVal e As
DataGridSortCommandEventArgs)
BindGrid(e.SortExpression)
End Sub
---------------------------------------------------
When I click the column name on the header, the grid
disappears. I do not understand where I have gone wrong.
Any help is appreciated.
Thanks,
Sudhir.