We help IT Professionals succeed at work.

Sort of the DataGrid In ASP.NET

vadimv
vadimv asked
on
 Hi Expert!

  I have following problem:
  I use ASP.NET.

  I need to make posiible sort of data grid:
  Here my Data Grid:
<asp:datagrid id="DataGrid1" runat="server" CellPadding="3" GridLines="None" width="100%" AllowPaging="True" OnPageIndexChanged="ChangeGridPage" PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="False" AllowSorting="True">

<HeaderStyle Font-Bold="True" HorizontalAlign="Right"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="InsertDate" HeaderText="úàøéê äæðä" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:BoundColumn DataField="CandidateName" HeaderText="ùí" DataFormatString="{0}"></asp:BoundColumn>
<asp:BoundColumn DataField="UserName" HeaderText="äåæï ò''é" DataFormatString="{0}"></asp:BoundColumn>
<asp:HyperLinkColumn DataNavigateUrlField="CVFilePath" DataNavigateUrlFormatString="JavaScript: OpenWordFile('{0}');" DataTextField="CVFileName" HeaderText="÷åáõ ÷å''ç" DataTextFormatString="{0}"></asp:HyperLinkColumn>
<asp:HyperLinkColumn Text="òøéëä" DataNavigateUrlField="ID" DataNavigateUrlFormatString="JavaScript: OpenEditWindow({0});" HeaderText="òøéëä"></asp:HyperLinkColumn>
<asp:HyperLinkColumn Text="îçé÷ä" DataNavigateUrlField="ID" DataNavigateUrlFormatString="JavaScript: confirmToDelete({0});" HeaderText="îçé÷ä"></asp:HyperLinkColumn>
</Columns>
<PagerStyle NextPageText="äáà" PrevPageText="ä÷åãí" HorizontalAlign="Left" PageButtonCount="1"></PagerStyle>
</asp:datagrid>


I did't success to receive possibility sorting.

The problem is the header of grid is't link (this is text).

The reason is in using property AutoGenerateColumns="False"
But I need use this property for using column templates.

How can I receive ability sort grid with property AutoGenerateColumns="False".

Thanks.
Comment
Watch Question

Vadimv,

I had the same problem when I was making an example for someone here... try adding in your DataBoundColumns the tag : SortExpression="<datafieldname>"

It's important that SortExpression has the same name as your datafield property.  Because that's what will be used to sort on.

The ASP.NET will add the link in the header so you can sort on it.

Greetings
BRONZE EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[points to private_void]

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

hongjun
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.