AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Sorting
Posted by Nilesh Kale on  11/12/2008 5:37:16 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Dear All,

I am searching code for sorting in asp.net.if possible give the code
Rest is at my end.
thanks in advance.



Post Your Reply Post New Question

 Viewer's Reply
Sorting
Answered By Chapidi on 11/20/2008 4:42:22 AM
Hi,
put these lines in ur aspx page
..................................................

<asp:GridView ID="grdvCommissionAgentinfo" runat="server" Width="100%" AllowSorting="True" OnSorting="grdvCommissionAgentinfo_Sorting" AutoGenerateColumns="False" BackColor="White" GridLines="none" CellSpacing="0"> </asp:GridView>
take two hidden variables.
<input id="hidSortKey" type="hidden" runat="server" />
<input id="hidOrderKey" type="hidden" runat="server" />

put these lines in ur aspx.cs page
....................................................................

protected void grdvCommissionAgentinfo_Sorting(object sender, GridViewSortEventArgs e)
{
lblMessage.Text = "";
string StrSortKey;
StrSortKey = e.SortExpression;

if (hidSortKey.Value == StrSortKey)
{
if (hidOrderKey.Value == "ASC")
{
hidOrderKey.Value = "DESC";
}
else
{
hidOrderKey.Value = "ASC";
}

}
else
{
hidSortKey.Value = StrSortKey;
hidOrderKey.Value = "ASC";
}

SqlConnection con = new SqlConnection(connection);
con.Open();
SqlDataAdapter adap = new SqlDataAdapter("Select * from CommissionAgent_Info order by " + hidSortKey.Value + " " + hidOrderKey.Value, con);
DataSet ds = new DataSet();
adap.Fill(ds);
grdvCommissionAgentinfo.DataSource = ds;
grdvCommissionAgentinfo.DataBind();
}
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The Art & Science of JavaScript - Free 100 Page Preview!
Easing the Migration to Microsoft SQL Server 2005
Building a Web Application Security Program