Tuesday 18 June 2013

Passing GridView Data To DataTable In ASP.NET

 In This Article, I would like to explain about the GridView BoundField And TemplateField in ASP.NET.
GridView Is Used To Display Data From Database Tables In Grid Format.
To Display The GridView, We Use The Tag
<asp:GridView runat="server"> </asp:GridView>
Here runat =”server” is used in ASP.NET To represent that the code run on server side (not in client side).
And Columns tag is used to display the columns <Columns> </Columns>
With In The Columns We Use BoundField or TemplateField tags To Display The Data From The Database Tables.
Main Difference Between BoundField And Template Field is
BoundField:
BoundField Is Used To Display Only The Values In Text Format
<asp:BoundField DataField="EmployeeID"HeaderText="Employee ID"
                    SortExpression="EmployeeID" />
In The Above Example DataField Is The Data Field Name Of The DataSource And HeaderText Is Used To Display The Header Text Name
And SortExpression Is Used To Display The Values In Sorting Order.
TemplateField:
Template Field Is Used To Mix The WebControls i.e Displaying Images, CheckBoxes, ImageButtons, Buttons.. etc.
<asp:TemplateField HeaderText="Product">
   <ItemTemplate>
    <asp:Image ID="ProductImage" runat="server" ImageUrl='<%#Eval("ProductImage") %>' Height="150px" Width="150px"/>
    </ItemTemplate>
 </asp:TemplateField>
In The Above Example, ItemTemplate Property Is Used To Display The Custom Content In The TemplateField.
By Using The Image Tag, We Are Displaying Image By Giving ImageUrl From The DataSource In The TemplateField Of Column.


The Below Link Shows The Example Programs Using BoundField And TemplateField of GridView Are Displaying As DataTables


Download

Download

No comments:

Post a Comment

Note: only a member of this blog may post a comment.