LinkButton in ItemTemplate : DataList « ADO.net Database « ASP.Net






LinkButton in ItemTemplate

<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server" language="VB">
    Sub Page_Load(sender as Object, e as EventArgs)
      If Not Page.IsPostBack then
        BindData()
      End If
    End Sub
    
    Sub BindData()
       Const strConnString as String = "server=localhost;uid=sa;pwd=;database=pubs"
       Dim objConn as New SqlConnection(strConnString)
    
       Const strSQL as String = "SELECT * FROM titles"
       Dim objCmd as New SqlCommand(strSQL, objConn)

       objConn.Open()

       dlTitles.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
       dlTitles.DataBind()

      objConn.Close()
    End Sub
    
    Sub dlTitles_ItemCommand(sender as Object, e as DataListCommandEventArgs)
      If e.CommandName = "Details" then
      End If
    End Sub

</script>
<form runat="server">
  <asp:DataList runat="server" id="dlTitles"
       OnItemCommand="dlTitles_ItemCommand">
    <ItemTemplate>
      <b>Title:</b> <%# DataBinder.Eval(Container.DataItem, "title") %>
      <br />
      [<asp:LinkButton runat="server" id="btnDetails" 
           Text="View Book Details" CommandName="Details" />]
    </ItemTemplate>
    
    <SeparatorTemplate>
      <hr>
    </SeparatorTemplate>
  </asp:DataList>
</form>

 








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.datalist and ItemTemplate
6.Set the DataSource to a String array of file names
7.Bind the Hashtable to the repeater