datagrid not sorting

G

gane

Hi

I have a datagrid with bound columns generated in code behind with
allowsorting set to true and OnSortCommand set to a sort function. I can see
the sorted results only if i remove the autogeneratecolumns = false,
otherwise i am not getting the results.
It is not getting to the dgresults_sort function when i clicked on the
column_header link.
Any thing i am missing in my code?

code:
<tr>
<td><asp:datagrid id="dgresults" runat="server"
CssClass="GridHeaderTemplate" GridLines="None" AllowSorting="True"
CellSpacing="1" CellPadding="1"
OnItemDataBound="dgresults_ItemDataBound" OnSortCommand="dgresults_sort"
AutoGenerateColumns =False>
<AlternatingItemStyle
cssclass="GridAlternatingItemTemplate"></AlternatingItemStyle>
<ItemStyle CssClass="GridItemTemplate"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="verdana"
BorderWidth="2px" ForeColor="white" BorderStyle="None"
BackColor="Gray"></HeaderStyle>
</asp:datagrid></td>
</tr>

codebehind:
public void dgresults_sort(object sender, DataGridSortCommandEventArgs e)

{

SortField = (string)e.SortExpression;

CreateDataSource();

}
 
C

Curtis

Where are your columns defined? Setting AutoGenerateColumns=False
should not display any columns based on the code you've shown. Try
defining a couple of colums on the datagrid.

Curtis
 
G

gane

I have my columns defined in the createdatasource() function.
The datagrid displays fine on postback on click of a button. But
it is not going to the dgresults_sort method when i clicked on the datagrid
header with results.
i am not calling the createdatasource() in page postback method.
doesn't sortcommand work the same way as button click?
public void dgresults_sort(object sender, DataGridSortCommandEventArgs e)

{

SortField = (string)e.SortExpression;

CreateDataSource();

}

private void btnSearch_ServerClick(object sender, System.EventArgs e)

{

CreateDataSource();

}
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top