datalist and ItemTemplate : DataList « ADO.net Database « ASP.Net






datalist and ItemTemplate

<%@ Page %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    Sub Page_Load(sender as Object, e as EventArgs)
       Const strConnString as String = "server=localhost;uid=sa;pwd=;database=pubs"
       Dim objConn as New SqlConnection(strConnString)
    
      Const strSQL as String = "SELECT * FROM authors"
      Dim objCmd as New SqlCommand(strSQL, objConn)
    
      Dim objDA as New SqlDataAdapter()
      objDA.SelectCommand = objCmd
    
      Dim objDS as New DataSet()
      objDA.Fill(objDS)
      objConn.Close()
    
      dlAuthors.DataSource = objDS
      dlAuthors.DataBind()
    End Sub

</script>
<asp:datalist id="dlAuthors" runat="server"
     RepeatColumns="4">
  <ItemTemplate>
    <b><%# DataBinder.Eval(Container.DataItem, "au_lname") %>,
    <%# DataBinder.Eval(Container.DataItem, "au_fname") %></b>
  </ItemTemplate>
</asp:datalist>

 








Related examples in the same category

1.asp:datalist: repeat column, repeat directions, gridlines,
2.Bind data to asp:datalist
3.Bind data source to asp:DataList
4.DataList data binding with objects
5.Set the DataSource to a String array of file names
6.Bind the Hashtable to the repeater
7.LinkButton in ItemTemplate