Hello there,
the user should be able to sort some columns, this can be normal text (names), numbers or dates.
I found this example on your page: http://help.infragistics.com/Help/NetAdvantage/ASPNET/2012.1/CLR4.0/html/WebDataGrid_Sorting.html
The example just binds directly to the data, in my case, I have Templates as columns:
<ig:TemplateDataField Key="Name" Width="260px">
<HeaderTemplate>
<asp:Label ID="lblNameHeader" runat="server">Name</asp:Label><br>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkBtnName" runat="server" CausesValidation="False" CommandName="Link"
Width="200px" Font-Underline="true" Style="white-space: pre-wrap;">linkBtnName</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<div class="rowSelectEdit">
<stgwc:TextEdit runat="server" ID="txtIndvId" Width="0px" />
<asp:Label runat="server" ID="lblNameEdit" CssClass="lblRequiredField" Style="white-space: pre-wrap;">
</asp:Label>
<stgwc:ImageLinkButton ID="ibutChange" runat="server" CssClass="icoButton" ToolTip="Opens a search page where you can find your roles entry."
CausesValidation="False" ImageUrl="Images/base/Icons/16x16/media_play_green.png"
CommandName="SearchIndOrgInsert">
</stgwc:ImageLinkButton>
</div>
</FooterTemplate>
</ig:TemplateDataField>
In the Code behind, I set the sorting like this:
private void InitializeSortButtons()
{
dgrRoles.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.
Sorting>();
dgrRoles.Behaviors.Sorting.SortingMode =
SortingMode.Single;
dgrRoles.Behaviors.Sorting.SortedColumns.Add(dgrRoles.Columns[COL_NAME], Infragistics.Web.UI.
SortDirection.Ascending);
SortDirection.Descending);
}
const string COL_NAME = "Name";
But I get an error on the preRender:
"An unexpected error occured. Cannot find column Name."
Am I missing something? Is it possible to sort with the template fields?
BTW: Is there a possibility to format code better?
Thanks for your response!
Hi Matthias,
The WDG will not sort Templated columns by default, since in cases where the datasource is able to sort we use the datasource for sorting. Also the grid has no idea what part of the template is sortable, as in do we sort by the label text or label id or what if you have a link, should the URL be sorted or the text, ect?
You can implement sorting for your templated columns though, as you know which parts of the template should be sortable for your particular application/page. This can be achieved in multiple ways. I am attaching two different websites which show you two different ways to implement it.
In order to run the attach sample please change the Infragistics dll reference in the Web.Config and ASPX files to the version that you are currently using. Currently the style directory is set in the Web.Config file to be located in "http://localhost/ig_res12.1" virtual directory, if this is not where you have your Infragisitcs styles installed please change this as well.
Thank You,
Olga
ASP.NET Principal Software Engineer
Infragistics, Inc.
Forgot to attach the 2nd solution. Here it is