Datagrid Sort problem with Dynamic

M

Mike

I have a datagrid on an asp page defined as follows:

<asp:datagrid id="DataGrid1" runat="server" BackColor="DeepSkyBlue"
BorderStyle="Ridge" AllowSorting="True" BorderColor="Linen"
AutoGenerateColumns="False" AllowPaging="True" EnableViewState="True"
PageSize="500">
<SelectedItemStyle Wrap="False"></SelectedItemStyle>
<AlternatingItemStyle Wrap="False" BackColor="White"></AlternatingItemStyle>
<ItemStyle Font-Size="X-Small" Wrap="False" Height="22px"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Wrap="False" HorizontalAlign="Center"
BackColor="AntiqueWhite"></HeaderStyle>
<PagerStyle PageButtonCount="50" Wrap="False"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

I dynamically add bound columns using the following:

Dim MyCol As System.Web.UI.WebControls.BoundColumn
DataGrid1.Columns.Clear()
MyCol = New System.Web.UI.WebControls.BoundColumn
MyCol.HeaderText = "Call Date/Time"
MyCol.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
MyCol.DataField = "Call_Date_Time"
MyCol.ItemStyle.Wrap = False
MyCol.ReadOnly = False
MyCol.SortExpression = "Call_Date_Time"
DataGrid1.Columns.Add(MyCol)

This all works fine except the Datagrid1_SortCommand never fires. The only
way I could get it to work was to define the bound columns on the html page
which sort of defeats the purpose of creating them dynamically. Any help
would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top