Sorting when the page is loaded the first time

Discussion in 'ASP .Net' started by Patrick Jox, Jun 30, 2006.

  1. Patrick Jox

    Patrick Jox Guest

    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
    Patrick Jox, Jun 30, 2006
    #1
    1. Advertising

  2. Patrick Jox

    raikinda Guest

    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!..
    raikinda, Jun 30, 2006
    #2
    1. Advertising

  3. Patrick Jox

    Patrick Jox Guest

    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>



    "raikinda" <> schrieb im Newsbeitrag
    news:...
    >
    > 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!..
    >
    Patrick Jox, Jun 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,309
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Alan Silver
    Replies:
    2
    Views:
    447
    Alan Silver
    Feb 24, 2005
  3. =?Utf-8?B?U3RldmUgQm9vdGg=?=

    Event fails to fire first time in dynamically loaded user control(

    =?Utf-8?B?U3RldmUgQm9vdGg=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    584
    =?Utf-8?B?U3RldmUgQm9vdGg=?=
    Apr 6, 2005
  4. Lucas Tam
    Replies:
    0
    Views:
    1,050
    Lucas Tam
    Jun 22, 2005
  5. Udo Corban
    Replies:
    0
    Views:
    3,826
    Udo Corban
    Jan 23, 2004
Loading...

Share This Page