By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

GridView Sorting Issue

P: n/a
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.

Nov 8 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.