LinkButton in ItemTemplate : DataList « ADO.net Database « 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 » ADO.net Database » DataList 
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
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.