GridView Sorting Issue

Discussion in 'ASP .Net' started by jobo, Nov 8, 2006.

  1. jobo

    jobo Guest

    Hey there,

    I'm having a problem getting sorting to work.

    Here's what the GridView looks like:



    "server" ID="updt1" Mode="Conditional">


    "false"
    AllowSorting="true"

    AlternatingRowStyle-CssClass="altrow2"
    AutoGenerateColumns="false"
    BorderColor="silver"
    BorderStyle="Solid"
    BorderWidth="1px"
    CaptionAlign="Left"
    EmptyDataText="No data available."

    EmptyDataRowStyle-CssClass="altrow2"
    GridLines="Horizontal"
    HeaderStyle-CssClass="headerx"
    HeaderStyle-Font-Bold="false"
    Id="gridView"

    OnSorting="gv_OnSorting"
    OnRowCreated="gv_RowCreated"
    OnRowDataBound="gv_RowDatabound"
    RowStyle-CssClass="row2"

    Runat="server"
    ShowFooter="false"
    Width="100%" >

    "fullname"
    HeaderStyle-CssClass="hpad"

    HeaderStyle-HorizontalAlign="Left"
    HeaderText=" Name"
    ItemStyle-CssClass="hyper"

    ItemStyle-Width="180"
    SortExpression="fullname"
    />
    "hpad"
    HeaderText="Branch"
    HtmlEncode="false"
    ItemStyle-Width="200"
    SortExpression="officename"
    />
    "name_county"
    HeaderStyle-CssClass="hpad"
    HeaderText="County"
    HtmlEncode="false"
    ItemStyle-CssClass="vline"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="90"

    SortExpression="name_county" />


    "active"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"
    HeaderText="Total"
    HtmlEncode="false"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"
    SortExpression="active" />
    "activeresale"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"
    HeaderText="Resale"
    HtmlEncode="false"
    ItemStyle-Width="50"

    ItemStyle-HorizontalAlign="center"

    SortExpression="activereslae" />
    "activerefi"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"
    HeaderText="Refi"
    HtmlEncode="false"
    ItemStyle-Width="50"

    ItemStyle-HorizontalAlign="center"
    SortExpression="activerefi"
    />
    "resalepct"
    DataFormatString="{0:p1}"
    HeaderStyle-CssClass="hpad"

    HeaderText="Resale<br/>Mix"

    HtmlEncode="false"
    ItemStyle-CssClass="vline"

    ItemStyle-HorizontalAlign="right"
    ItemStyle-Width="55"
    SortExpression="resalepct"
    />
    "escrpo"
    DataFormatString="{0:C2}"
    HeaderStyle-CssClass="hpad"

    HeaderText="per<br/>Order"
    HtmlEncode="false"
    ItemStyle-CssClass="vline"

    ItemStyle-HorizontalAlign="right"
    ItemStyle-Width="75"
    SortExpression="escrpo" />
    "opentm"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"
    HeaderText="New"
    HtmlEncode="false"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"
    SortExpression="opentm" />
    "closedtm"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"

    HeaderText="Closed"
    HtmlEncode="false"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"
    SortExpression="closedtm"
    />
    "hpad"
    HeaderText="Proj."
    HtmlEncode="false"
    ItemStyle-CssClass="vline"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"

    SortExpression="projectedtm" />
    "escrowrank"
    DataFormatString="{0:N0}"
    HeaderStyle-CssClass="hpad"


    HeaderText="Closed<br/>Esc."
    HtmlEncode="false"

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"
    SortExpression="escrowrank"
    />
    "revenuerank"
    DataFormatString="{0:N0}"

    FooterStyle-HorizontalAlign="center"
    HeaderStyle-CssClass="hpad"
    HtmlEncode="false"

    HeaderText="Closed<br/>Rev."

    ItemStyle-HorizontalAlign="center"
    ItemStyle-Width="50"

    SortExpression="revenuerank" />




    "gridView" EventName="Sorting" />






    protected void load_gv(string _sproc, string _param)
    {
    using (FADataBase faDb = DBHelper.GetDatabase(FAUser))
    {
    string errorString;
    try
    {
    DataTable dt = faDb.oneparamDt(_sproc, _param, out
    errorString);
    DataView dv = new DataView(dt);
    gridView.DataSource = dv;
    gridView.DataBind();
    }
    catch (dbExecException sex)
    {
    errorMessage(sex.ToString());
    }
    }
    }

    public void gv_OnSorting(object sender, GridViewSortEventArgs e)
    {
    GridView tempG = (GridView)sender;
    string asdf = tempG.ID.ToString();

    if ((string)ViewState["sort"] == "desc" &&
    (string)ViewState["lastSort"] == e.SortExpression)
    {
    ViewState["sort"] = "asc";
    e.SortDirection = SortDirection.Ascending;
    }
    else
    {
    ViewState["sort"] = "desc";
    e.SortDirection = SortDirection.Descending;
    }

    ViewState["lastSort"] = e.SortExpression;


    }

    The load_gv() basically gets a stored procedure name and then gets a
    DataView and binds it to the GridView. My custom OnSorting method
    doesn't work. Nothing sorts at all. However, even when I turn off
    custom sorting and revert back to the standard sort, nothing sorts
    there either. Is it something to do with the DataView? Usually I use a
    SQLDataSource. Does anyone know what the issue is? Thanks.
    jobo, Nov 8, 2006
    #1
    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. Cirene
    Replies:
    1
    Views:
    369
    gnewsgroup
    Nov 4, 2007
  2. Replies:
    2
    Views:
    1,392
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    363
    Jason
    Oct 4, 2006
  4. jobs
    Replies:
    2
    Views:
    1,556
  5. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    458
    Michael Budash
    Oct 11, 2003
Loading...

Share This Page