Loading

GridView With an ItemTemplate

Submitted by: 


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

  1. <asp:SQLDataSource ID="DS1"
  2. Runat="Server"
  3. SelectCommand = "Select FirstName, LastName, Title, BirthDate from Employees"
  4. ConnectionString="<%$ ConnectionStrings:YourConnStringGoesHere %>">
  5. </asp:SQLDataSource>

3).Insert the following code in your aspx file

  1. <asp:GridView ID="gv1"
  2. AutoGenerateColumns="False "
  3. Runat="Server"
  4. DataSourceID="DS1"
  5. AllowPaging = "True"
  6. PageSize = "5"
  7. PagerSettings-Mode = "Numeric">
  8. <columns>
  9. <asp:TemplateField HeaderText="put your header text">
  10. <ItemTemplate> <b><font color="#0000FF">Name</font>:</b>
  11. <%#Container.DataItem("firstname")%> <%#Container.DataItem("columnename")%><br />
  12. <b><font color="#FF0000">Hire Date</font>: </b>
  13. (<%# formatdatetime(Container.DataItem("Birthdate"),vbshortdate)%>) <br />
  14. <b>Title: </b> <i><font Size="2"><%#Container.DataItem("title")%></font></i>
  15. </ItemTemplate>
  16. </asp:TemplateField>
  17. </columns>
  18. </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




Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.