Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2005, 08:51 PM
Authorized User
 
Join Date: Nov 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataList Question

Is that possible to add a <asp:button> to use as itemtemplate of datalist control, so when user click on that button ASP.NET can know which record does the user clicking on.

If possible, please let me know how to implements in

For question asking, please made sure that your question is as similar as possible while providing enought level of details!
Since not all peoples, like to read large amounts of text just for reading or requirement and waste the answer time to read your text
__________________
For question asking, please made sure that your question is as similar as possible while providing enought level of details!
Since not all peoples, like to read large amounts of text just for reading or requirement and waste the answer time to read your text
 
Old April 19th, 2005, 06:02 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Hope this helps

Code:
<%@ Page Language="C#" %>
<script runat="server">
    System.Data.DataSet GetAuthors()
    {
        string connectionString = "server=\'(local)\'; user id=\'uid\'; password=\'pwd\'; database=\'pubs\'";
        System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

        string queryString = "SELECT [authors].[au_lname], [authors].[au_id] FROM [authors]";
        System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
        dbCommand.CommandText = queryString;
        dbCommand.Connection = dbConnection;

        System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
        dataAdapter.SelectCommand = dbCommand;
        System.Data.DataSet dataSet = new System.Data.DataSet();
        dataAdapter.Fill(dataSet);

        return dataSet;
    }

    void Page_Load(object sender, EventArgs e)
    {
        dlAuthors.DataSource = GetAuthors();
        dlAuthors.DataBind();
    }

    void cmdClick_Command(object sender, CommandEventArgs e)
    {
        lblSelected.Text = e.CommandArgument.ToString();
    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <table>
            <tr>
                <td>
                    <asp:Label id="lblSelected" runat="server" forecolor="Red">Select From List</asp:Label></td>
            </tr>
            <tr>
                <td>
                    <asp:DataList id="dlAuthors" runat="server" BorderStyle="None" GridLines="Both" BorderWidth="1px" BorderColor="#CC9966" BackColor="White" CellPadding="4">
                        <ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
                        <FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
                        <HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
                        <SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
                        <ItemTemplate>
                            <asp:button id="cmdClick" OnCommand="cmdClick_Command" Text="Select" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "au_lname") %>'></asp:button>
                            &nbsp;<asp:Label id="Label1" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "au_lname") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
Datalist question sbo Classic ASP Databases 2 May 31st, 2005 09:39 PM
DataList <a Href> Question in Roles.aspx bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 5 October 5th, 2004 02:54 PM
Datalist , Datagrid, or Repeater question olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 7 June 1st, 2004 01:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.