datalist取消编辑状态
前台代码:<asp:DataList ID="DataList1" runat="server"
onitemcommand="DataList1_ItemCommand"
oncancelcommand="DataList1_CancelCommand"
onupdatecommand="DataList1_UpdateCommand" >
<EditItemTemplate>
<table>
<tr>
<td align="left" valign="middle" width="146">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Imageurl")%>' />
</td>
<td width="115">
<span class="STYLE3"><strong>
<asp:Label ID="name" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</strong></span>
</td>
<td width="88">
<span class="STYLE3"><strong>
<asp:Label ID="price" runat="server" Text='<%# Eval("price") %>'></asp:Label>
</strong></span>
</td>
<td width="100">
<asp:TextBox ID="TextBox1" runat="server" Height="16px"
style="margin-left: 5px" Text='<%# Eval("quantity")%>' Width="45px"></asp:TextBox>
</td>
<td width="121">
<span class="STYLE3"><strong>
<asp:Label ID="notes" runat="server" Text='<%# Eval("notes") %>'></asp:Label>
</strong></span>
</td>
<td width="88">
<span class="STYLE3"><strong>
<asp:Label ID="total" runat="server" Text='<%# Eval("total") %>'></asp:Label>
</strong></span>
</td>
<td align="right" width="87">
<asp:LinkButton ID="LinkButton2" runat="server" CommandNam="Update" Text="更新"></asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemTemplate>
<table >
<tr>
<td width="146" align="left" valign="middle">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Imageurl")%>'/>
</td>
<td width="115"><span class="STYLE3"><strong>
<asp:Label ID="name" runat="server" Text='<%# Eval("name") %>'></asp:Label></strong>
</span></td>
<td width="88" ><span class="STYLE3"><strong><span class="STYLE3">
<asp:Label ID="price" runat="server" Text='<%# Eval("price") %>'></asp:Label>
</span></strong></span></td>
<td width="100"><span class="STYLE3"><strong><span class="STYLE3">
<asp:Label ID="quan" runat="server" Text='<%# Eval("quantity") %>'></asp:Label>
</span></strong></span></td>
<td width="121"><span class="STYLE3"><strong><span class="STYLE3">
<asp:Label ID="notes" runat="server" Text='<%# Eval("notes") %>'></asp:Label>
</span></strong></span></td>
<td width="88" ><span class="STYLE3"><strong><span class="STYLE3">
<asp:Label ID="total" runat="server" Text='<%# Eval("total") %>'></asp:Label>
</span></strong></span></td>
<td width="87" align="right" >
<asp:LinkButton ID="LinkButton1" runat="server" Text="编辑"
CommandName="Edit"></asp:LinkButton><asp:Label ID="itemid" runat="server" Text='<%# Eval("id") %>' Visible="false"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台代码:
public partial class Car : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindDatalist();
}
}
private void bindDatalist()
{
//获取传入购物车,绑定数据
this.DataList1.DataSource = Session["Cartit"];
int count = 0;
foreach (CartItem item in (ICollection)Session["cartit"])
{
count++;
}
this.count.Text = count.ToString();
this.DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (("Edit"))
{
this.DataList1.EditItemIndex = e.Item.ItemIndex;
bindDatalist();
}
//else if (("Update"))
//{
// Label la1 =(Label) e.Item.FindControl("itemid");
// int itemid=int.Parse(la1.Text);
// foreach (CartItem item in (ICollection)Session["cartit"])
// {
// if (item.Id==itemid)
// {
// item.Quantity++;
// }
// }
// DataList1.EditItemIndex = -1;
// bindDatalist();
//}
}
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = -1;
bindDatalist();
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
Label la1 = (Label)e.Item.FindControl("itemid");
int itemid = int.Parse(la1.Text);
foreach (CartItem item in (ICollection)Session["cartit"])
{
if (item.Id == itemid)
{
item.Quantity++;
}
}
Page.RegisterStartupScript("msg", "<script>alert('更新成功!')</script>");
DataList1.EditItemIndex = -1;
bindDatalist();
}
这是一个购物车模块
进入编辑状态之后,输入新的商品熟练,点击更新按钮,从新绑定,但是,既不执行ItemCommand中关于update 的代码,也不执行Update事件,请问到底为什么,谢谢,这是我全部的分