Sorting when the page is loaded the first time

P

Patrick Jox

Hi,
I have am using ObjectDataSource and GridView to display data on my ASP.NET
webform. I also implemented a comparer class to be able to sort the data by
clicking on the column header.
My problem is that the first time the page is loaded the sort paramter is
passed a zero lenght string. So the gridview is not sorted.

I'm sure this is a very small thing but I can't find it:
How can I define the column that is used for sorting the first time the page
is loaded (!PostBack)?

Thanks
Patrick
 
R

raikinda

Patrick Jox yazdi:
Hi,
I have am using ObjectDataSource and GridView to display data on my ASP.NET
webform. I also implemented a comparer class to be able to sort the data by
clicking on the column header.
My problem is that the first time the page is loaded the sort paramter is
passed a zero lenght string. So the gridview is not sorted.

I'm sure this is a very small thing but I can't find it:
How can I define the column that is used for sorting the first time the page
is loaded (!PostBack)?

Thanks
Patrick

Hi,
if i am not wrong, you want to sort gridview for a default column,
right? if your answer is yes, then set your selected string value one
of the columns by default. i hope that was your question!..
 
P

Patrick Jox

Hi Raikinda,
yes this is exact what I want to do. I am not sure if I understand what you
mean. But as far as I see I have done it like this.
I set the Attribute SortParameterName to SortExpression and then assigned
the value 'Height' (which is one of my columns) in the SelectParameters
section.
But still this doesn't work. Below you'll find a piece of code...

Patrick

Here is the piece of code:
<asp:ObjectDataSource ID="DisplayData" runat="server"
DeleteMethod="DeleteDisplay"
SelectMethod="GetAllDisplays"
TypeName="kapaya.smsportal.BusinessTier.Display"
SortParameterName="SortExpression">
<SelectParameters>
<asp:parameter Name="SortExpression" DefaultValue="Height" />
</SelectParameters>
<DeleteParameters>
<asp:parameter Name="Guid" />
</DeleteParameters>
</asp:ObjectDataSource>

<asp:GridView ID="DisplayList" runat="server" DataKeyNames="Guid"
AllowSorting="True"
AutoGenerateColumns="False" BorderStyle="None" CellPadding="2"
DataSourceID="DisplayData"
AllowPaging="True" BackColor="White" CssClass="Grid">
<RowStyle HorizontalAlign="Left" CssClass="row1" />
<HeaderStyle CssClass="grid-header" HorizontalAlign="Left" />
<EmptyDataTemplate>
<asp:Label ID="Label10" runat="server" Text="Label">Im Moment sind
keine Displays in der Liste anzuzeigen.</asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="Guid" HeaderText="Guid" SortExpression="Guid"
Visible="False"/>
<asp:BoundField DataField="Height" HeaderText="Height"
SortExpression="Height" />
<asp:BoundField DataField="Width" HeaderText="Width"
SortExpression="Width" />
<asp:BoundField DataField="Colors" HeaderText="Colors"
SortExpression="Colors" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type"
/>
<asp:CommandField DeleteImageUrl="~/images/icon-delete.gif"
ShowDeleteButton="True"
ButtonType="Image" >
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:CommandField>

</Columns>
</asp:GridView>
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top