Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with sorting dynamically created datagrid

Status
Not open for further replies.

liuk

Programmer
Jan 16, 2006
54
IT
hi,
in my application i create the columns of a datagrid at runtime (excep the first one). I allow sorting on datagrid but when i try to sort the datagrid gets empty.
This is the code i wrote :


Private Sub CreateDataGrid()
Dim boundCol As BoundColumn


While dgPreview.Columns.Count > 1
dgPreview.Columns.RemoveAt(dgPreview.Columns.Count - 1)
End While



With dgPreview
.AllowSorting = True
.AutoGenerateColumns = False


.DataKeyField = "Id"

boundCol = New BoundColumn
boundCol.DataField = "Id"
boundCol.Visible = False
.Columns.Add(boundCol)

' add other columns


' add handler
AddHandler dgPreview.SortCommand, AddressOf dgPreview_SortCommand

end sub



Private Sub dgPreview_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
CreateDataGrid()
BindDataGrid()
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top