Search
We can customise the way a GridView look by using Item Template, we can use in our own convenience
Steps:
1). In our example we are using Northwind Database, table Employees
2). use the following SQLDataSource
<asp:SQLDataSource ID="DS1" Runat="Server" SelectCommand = "Select FirstName, LastName, Title, BirthDate from Employees" ConnectionString="<%$ ConnectionStrings:YourConnStringGoesHere %>"> </asp:SQLDataSource>
3).Insert the following code in your aspx file
<asp:GridView ID="gv1" AutoGenerateColumns="False " Runat="Server" DataSourceID="DS1" AllowPaging = "True" PageSize = "5" PagerSettings-Mode = "Numeric"> <columns> <asp:TemplateField HeaderText="put your header text"> <ItemTemplate> <b><font color="#0000FF">Name</font>:</b> <%#Container.DataItem("firstname")%> <%#Container.DataItem("columnename")%><br /> <b><font color="#FF0000">Hire Date</font>: </b> (<%# formatdatetime(Container.DataItem("Birthdate"),vbshortdate)%>) <br /> <b>Title: </b> <i><font Size="2"><%#Container.DataItem("title")%></font></i> </ItemTemplate> </asp:TemplateField> </columns> </asp:GridView>
and you will get the GridView with ItemTemplate.
About the author:
PlanetSourceCode.in is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development
- 2314 reads



Post new comment