CSharp Datalist And Itemtemplate – ADO.Net Database

<%@ 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>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.