Add DataRow to asp:DataTable : DataRow « Data Binding « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » Data Binding » DataRow 
Add DataRow to asp:DataTable

<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<html>
<head>
   <title>List Control Example</title>
   <script runat="server">
      Sub Page_Load()
         MyRepeater.DataSource = CreateData()
         MyRepeater.DataBind()
      End Sub
      Function CreateData() As DataTable
         Dim DT As New DataTable()
         Dim Row1, Row2, Row3, Row4 As DataRow
         DT.Columns.Add(New DataColumn("name", System.Type.GetType("System.String")))
         DT.Columns.Add(New DataColumn("city", System.Type.GetType("System.String")))
         Row1 = DT.NewRow()
         Row1("name""Name Here"
         Row1("city""City Here"
         DT.Rows.Add(Row1)
         Row2 = DT.NewRow()
         Row2("name""Another Name Here"
         Row2("city""City 2 Here"
         DT.Rows.Add(Row2)
         Row3 = DT.NewRow()
         Row3("name""Name 3"
         Row3("city""City 3"
         DT.Rows.Add(Row3)
         Row4 = DT.NewRow()
         Row4("name""Name 4"
         Row4("city""City 4"
         DT.Rows.Add(Row4)
         Return DT
      End Function
   </script>
</head>
<body>
   <h1>Control Templates Example</h1>
   <form runat="server">
      <asp:table id="MyTable" border="1" cellpadding="5" cellspacing="0" runat="server">
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               Repeater Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:repeater id="MyRepeater" runat="server">
                  <headertemplate>
                     <h3>Famous Composers' Birthplaces</h3>
                     <table cellpadding="5" cellspacing="0">
                        <tr>
                           <td>Name<hr/></td>
                           <td>City<hr/></td>
                        </tr>
                  </headertemplate>
                  <itemtemplate>
                        <tr>
                           <td><strong><%# DataBinder.Eval(Container.DataItem, "name"%><strong></td>
                           <td><%# DataBinder.Eval(Container.DataItem, "city"%></td>
                        </tr>
                  </itemtemplate>
                  <footertemplate>
                     </table>
                  </footertemplate>
               </asp:repeater>
            </asp:tablecell>
         </asp:tablerow>
      </asp:table>
   </form>
</body>
</html>

           
       
Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.