Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Saturday, December 7, 2013

Gridview header sorting using C#

In my previous post i explained, how to Search string pattern using sql on SQL i had explained how to Add Image in between Rows of a GridView using C#.
 
Now in this article i will explain one of the useful feature i.e Gridview Sorting.
you need to set the AllowSorting property as a True. and SortExpression Property of columns to the specific field name from the database.
Lets look at the below sample gridview code.
 
<asp:GridView ID="gvDetails" runat="server"  onsorting="gvDetails_Sorting" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="Your Name" SortExpression="FirstName">
<ItemTemplate>
<%#Eval("YourName")%>'/>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>

Now for sorting you need to create one public property which store the value of direction in the viewstate and base on that select query get fired.


public GetSortDir direction
{
  get
  {
    if (ViewState["SortingDir"] == null)
        {
            ViewState["SortingDir"] = GetSortDir.Ascending;
         }
         return (GetSortDir)ViewState["SortingDir"];
   }
   set
   {
       ViewState["SortingDir"] = value;
   }
}

Now check the gridview directon and base on viewstate it will get set the new direction.

    protected void gvDetails_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sortDirection = string.Empty;
        if (direction == sortDirection.Ascending)
        {
            direction = sortDirection.Descending;
            sortDirection = "Desc";
        }
        else
        {
            direction = sortDirection.Ascending;
            sortDirection = "Asc";
        }
       
        DataView sortedView = new DataView(BindGridView());
        sortedView.Sort = e.SortExpression + " " + sortDirection;
        gvDetails.DataSource = sortedView;
        gvDetails.DataBind();
    }


Here BindGridView() is the function which returns the datatable & it contain the query result.
that's it now check the gridview and click on the header and see the sorting effects get added in your gridview.
 
 
 

Saturday, August 29, 2009

Visual Studio 2010 for Web Developer

New version of VS 2010 get announced with new features and new look for web devlopes. they are mostly focusing on Dynamic data, MVC arch. and other great feature of Silverlight and some more runtime functionality get added.

Overview of Visual Studio 2010 - wed Development
Here is the Key area:
- Source View
- Web Development
- Desing View
- DB Deployment

On the Source view they are ading Html Snippets and some more features of Jscripts Intellisense.
on Web Development process some more web.config Trasformation features and web1 -click features.
and on Desing view - improve the CSS2.1 Supoort and some advance features.
DB Deployment get handle the Packaging and Deploying the databse with your applications

- You can view the presentation at PDC on this Topics
http://channel9.msdn.com/pdc2008/TL48/ (77.32 mins)

- yes you can download the beta version of Vs2010 from here
http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&displaylang=en

you can find more on Visual Studio, Visual Studio 2010 ,VS,VS 10,Web Application Projects,WAP,Web Deployment,MSDeploy

hope you like this .