Asp.net gridview features

Gridview is one of the advanced and mostly used control on asp.net. Bellow you can find some of the interesting features of gridview.

Paging  support:

Gridview control has built in paging and sorting support that provides developer less time to configure paging and sorting to present data on tabular format. Paging and sorting can be configured in two ways on gridview.

First way  is very simple bind the data to the gridview and configure the gridview. Here all the datas are preloaded on the memory and only required data are displayed as per the paginng information. This needs less configuration. The main disadvantage of this method is, if there are lots of lots of data (about thousands of data) , all the data are loaded first on memeory and only records for specific page is only displayed. This costs unncessary overhed to the server because to show only 10 records of the support page 10 you have to load all data.

Second method is using ObjectDataSource paging option along with Gridview Paging option to enable paging on the gridview. This method is much more efficient if there are lots of records. In this method gridview and objectdata source are configured on such a way that to fetch the data from the database server to fetch only the records of required number starting from the sepecfic rowindex.

Binding support:

There are two ways of binding data to the gridview. One way binding using the Eval method just to display the data and Two way binding using Bind method if you want to return value from the control to the gridivew if you have enabled inline editing functionality on the gridview.

Here is the example how you can bind using TemplateField on the gridview.

<asp:TemplateField HeaderText="Name" ShowHeader="True">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name")  %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

While binding using Eval Method you can use expression to bind two or more columns. If you want to use expression for multiple columsn, Bind method is not supported.

 <asp:TemplateField HeaderText="Name" ShowHeader="True">

     <ItemTemplate>

     <asp:Label ID="lblName" runat="server"
Text='<%# Eval("FirstName")  + " "  + Eval("LastName") %>'>
</asp:Label>

    </ItemTemplate>

</asp:TemplateField>

, ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...