DataList update / cancel event not firing

Discussion in 'C#' started by webcosmo, Sep 2, 2007.

  1. #1
    Hoping somebody can help me with this.
    I have a page with EnableViewState false
    Code is like below. And the update and cancel events located on editItemTemplate not firing.
    =================code ===============
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "(URL address blocked: See forum rules)">
    <html xmlns="(URL address blocked: See forum rules)">
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:Label ID="lbl" runat="server"></asp:Label>
    <asp:Button ID="Button3" runat="server" Text="Button" />
    <br /><br />
    <asp:DataList id="DataList1" runat="server"
    BorderColor="black"
    BorderWidth="1"
    GridLines="Both"
    CellPadding="3"
    CellSpacing="0"
    Font-Names="Verdana"
    Font-Size="8pt"
    Width="150px"
    HeaderStyle-BackColor="#aaaadd"
    AlternatingItemStyle-BackColor="Gainsboro"
    EditItemStyle-BackColor="lightgreen"
    OnEditCommand="DataList_EditCommand"
    OnUpdateCommand="DataList_UpdateCommand"
    OnCancelCommand="DataList_CancelCommand"
    >
    <HeaderTemplate>
    Items
    </HeaderTemplate>
    <ItemTemplate>
    <asp:LinkButton id="button1" runat="server" Text="Edit" CommandName="edit" />
    Item
    </ItemTemplate>
    <EditItemTemplate>
    Item:
    <asp:Label id="Label1" runat="server"
    Text="Item" />
    <br>
    Quantity:
    <asp:TextBox id="Text1" runat="server"
    Text="1" />
    <br>
    Price:
    <asp:TextBox id="Text2" runat="server"
    Text="$55.00" />
    <br>
    <asp:Button ID="btn" CommandName="update" Text="update" runat="server" />
    <asp:Button ID="Button2" CommandName="cancel" Text="cancel" runat="server" />
    </EditItemTemplate>

    </asp:DataList>


    </form>
    </body>
    </html>


    using System;
    using System.IO;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Web.Mail;
    using System.Text.RegularExpressions;
    using System.Data.SqlTypes;


    public partial class _Default : System.Web.UI.Page
    {
    private String connectionString;
    //page
    public DataTable Cart;
    public DataView CartView;

    private String commandString;
    private DataTable dataTable;

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected override void OnInit(EventArgs e)
    {
    BindList();

    base.OnInit(e);
    }


    void BindList()
    {
    dataTable = ***** //data retrieved from db
    DataList1.DataSource = dataTable;
    DataList1.DataBind();
    /*
    DataList1.DataSource = CartView;
    DataList1.DataBind();
    */
    }

    protected void DataList_EditCommand(Object Sender, DataListCommandEventArgs e)
    {
    Response.Write("edit clicked");
    DataList1.EditItemIndex = (int)e.Item.ItemIndex;
    BindList();
    }

    protected void DataList_CancelCommand(Object Sender, DataListCommandEventArgs e)
    {
    Response.Write("hello 1");
    //DataList1.EditItemIndex = -1;
    BindList();
    }

    protected void DataList_UpdateCommand(Object Sender, DataListCommandEventArgs e)
    {
    Response.Write("hello 2");
    BindList();
    }
    }
     
    webcosmo, Sep 2, 2007 IP
  2. webcosmo

    webcosmo Notable Member

    Messages:
    5,840
    Likes Received:
    153
    Best Answers:
    2
    Trophy Points:
    255
    #2
    This problem is related to rendering child controls on postback.

    Anybody, any clue?
     
    webcosmo, Sep 3, 2007 IP