C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Sorting


Posted Date: 30 Jun 2009    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: ElzMember Level: Gold    
Rating: 1 out of 5Points: 3



Sorting gridview columns



< asp:GridView ID="GridView1" runat="server" AllowSorting=true
onrowcommand="GridView1_RowCommand"
onpageindexchanging="GridView1_PageIndexChanging"
onsorting="GridView1_Sorting" >
< PagerSettings FirstPageText="Next" LastPageText="Previous" Mode="NumericFirstLast"
NextPageText="Next" PreviousPageText="Previous" />

< Columns >
< asp:BoundField DataField="Type" HeaderText="Project Type" SortExpression="fprojecttype"/>
< asp:BoundField DataField="Priority" HeaderText="Project Priority" SortExpression="fProject_priority_name"
< asp:BoundField DataField="Start Date" HeaderText="Start Date" SortExpression="START_DATE" />
< asp:BoundField DataField="Due Date" HeaderText="Due Date" SortExpression="END_DATE" />








protected void Page_Load(object sender, EventArgs e)
{
this.Sortdir = "ASC";
bind();//write fn for bind gridview

}


private String SortDir
{
get { return ViewState["Sortdir"].ToString(); }
set { ViewState["Sortdir"] = value; }
}


protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (GridView1.Rows.Count > 1)
{
GridView1.DataSource = get_prjects(e.SortExpression, this.Sortdir, Session["CompanyID"].ToString());
GridView1.DataBind();
if (this.Sortdir == "ASC")
{

this.Sortdir = "DESC";
}
else
{
this.Sortdir = "ASC";
}
}
else
{
fillgrid(str);
}
}




public DataSet get_projects(String strsortfield, String strExpression, string cid)
{
DataSet myds = new DataSet();

try
{
String StrQstring = "";
StrQstring = "select a,b from tbname where a. COMPANY_ID=" + cid + " order by " + strsortfield + " " + strExpression + "";


getDS(StrQstring, "gprojects");
if (APMDLStatus)
{
_status = ds;
_Status = true;
}
else
{
_Status = false;
}
}
catch (Exception ex)
{
_projmsg = ex.Message;
_Status = false;
}
return _tstatus;
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Sorting gridview  .  Gridview sorting  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Add text box in gridview at runtime
Previous Resource: Gridview in Asp.net
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use