ASP.Net/Data Binding/DataBinder

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

DataBinder.Eval

<%@ 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">
  <ItemTemplate>
    <b><%# DataBinder.Eval(Container.DataItem, "au_lname") %>,
    <%# DataBinder.Eval(Container.DataItem, "au_fname") %></b>
  </ItemTemplate>
</asp:datalist>