Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 February 16th, 2007, 03:47 AM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataList HELP with Updating

I cannot figure out how to get this simple DataList to update, I have the C# Beginning 2005 Databases - Watson, but I am just not getting it. Trie dusing Bind instead of Eval - no good. What do I need to do to edit the (int) L_Rank, (string) L_City and L_State? I am just not getting it. I have eight WROX books and an really confused. Any help GREATLY appreciated. Thank you.


<asp:DataList ID="DataList1" runat="server" DataSourceID="LinkInfoDataSource" OnEditCommand="myEditListHandler" OnCancelCommand="DataList1_CancelCommand" OnUpdateCommand="DataList1_UpdateCommand" >
<ItemTemplate>
            <asp:Label ID="L_IDLabel" runat="server" Text='<%# Eval("L_ID") %>'></asp:Label><br />
            <asp:Label ID="L_NameLabel" runat="server" Text='<%# Eval("L_Name") %>'></asp:Label><br />
            <asp:Label ID="L_RankLabel" runat="server" Text='<%# Eval("L_Rank") %>'></asp:Label><br />
            <asp:Label ID="L_CityLabel" runat="server" Text='<%# Eval("L_City") %>'></asp:Label><br />
            <asp:Label ID="L_StateLabel" runat="server" Text='<%# Eval("L_State") %>'></asp:Label><br />
            <asp:Button ID="Button1" runat="server" Text="Button" CommandName="edit" />
            <br />
        </ItemTemplate>
        <HeaderTemplate>
           <h3><b>
               <asp:Label ID="Label1" runat="server" BackColor="#FFC080" Font-Size="Larger" Text=" Basic Header Trial "></asp:Label></b>&nbsp;</h3>
        </HeaderTemplate>
        <SeparatorTemplate></SeparatorTemplate>
        <EditItemTemplate>
            EDIT Template<br />
            <asp:TextBox ID="L_IDTextBox" runat="server" Text='<%# Eval("L_ID") %>'></asp:TextBox><br />
            <asp:TextBox ID="L_NameTextBox" runat="server" Text='<%# Eval("L_Name") %>'></asp:TextBox><br />
            <asp:TextBox ID="L_RankTextBox" runat="server" Text='<%# Eval("L_Rank") %>'></asp:TextBox><br />
            <asp:TextBox ID="L_CityTextBox" runat="server" Text='<%# Eval("L_City") %>'></asp:TextBox><br />
            <asp:TextBox ID="L_StateTextBox" runat="server" Text='<%# Eval("L_State") %>'></asp:TextBox><br />
            <asp:Button ID="Button2" runat="server" Text="Update" CommandName="update" />
            <asp:Button ID="Button3" runat="server" Text="Cancel" CommandName="cancel" />
        </EditItemTemplate>
    </asp:DataList><asp:SqlDataSource ID="LinkInfoDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
        SelectCommand="SELECT [L_ID], [L_Name], [L_Rank], [L_City], [L_State] FROM [tblContractorLinkInfo] WHERE ([L_State] = @L_State)" >
        <SelectParameters>
            <asp:Parameter DefaultValue="va" Name="L_State" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>


CODE BEHIND *****

public partial class Basics : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { }

    protected void myEditListHandler(Object src, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = e.Item.ItemIndex;
        DataList1.DataBind();
    }
    protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
    }
    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    { }
}






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 not Updating.. slim182 ASP.NET 2.0 Basics 0 February 16th, 2007 12:48 PM
datalist sarah lee ASP.NET 1.0 and 1.1 Basics 0 October 18th, 2006 02:49 PM
Updating boolean values using datalist Scripts82 ASP.NET 1.0 and 1.1 Basics 1 September 20th, 2006 04:17 AM
DataList in DataList acko ASP.NET 1.0 and 1.1 Professional 3 July 9th, 2004 05:18 PM





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