简单响应DataList中的Button事件和Lable值
在<%@ Page Language="C#"...>上增加 enableEventValidation= "false " 这样子好像就没有那个回发或者或调无效参数无效的问题.

<asp:DataList ID="dtlShowByClick" runat="server" Height="1143px" Width="900px" OnItemCommand="dtlShowByClick_ItemCommand" OnItemDataBound="dtlShowByClick_ItemDataBound" >
<ItemTemplate>
<table style="width: 800px; height: 150px">
<tr>
<td rowspan="3" style="width: 170px">
<asp:Image ID="imgPicture" runat="server" ImageUrl='<%# Eval("PictureUrl") %>' /></td>
<td colspan="2" style="height: 48px">
编号:
<asp:Label ID="lblId" runat="server" Text='<%# Eval("ProductId") %>'></asp:Label>
<asp:Label ID="lblProduct_Name" runat="server" Text='<%# Eval("Name") %>'></asp:Label></td>
<td colspan="2" style="height: 48px">
描述:<asp:Label ID="Label3" runat="server" Text='<%# Eval("Remark") %>'></asp:Label><br />
</td>
</tr>
<tr>
<td style="width: 115px; height: 19px;">
原 价:<asp:Label ID="lblOldPrice" runat="server" Text='<%# Eval("OldPrice") %>'></asp:Label><br />
</td>
<td style="width: 115px; height: 19px;">
现 价:
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Price") %>'></asp:Label></td>
<td colspan="2" style="height: 19px">
备注:<asp:Label ID="lblremark" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td style="width: 115px; height: 18px;">
点击次数:<asp:Label ID="Label1" runat="server" Text='<%# Eval("Click") %>'></asp:Label></td>
<td style="width: 106px; height: 18px">
已售出数:<asp:Label ID="Label2" runat="server" Text='<%# Eval("SellCount") %>'></asp:Label></td>
<td style="width: 114px; height: 18px;">
<asp:Button ID="bttBuy" runat="server" Text="快速购买" Width="81px" /></td>
<td style="height: 18px">
<asp:Button ID="bttPutToCart" runat="server" Text="放进购物车" CommandName="BuyProduct" OnClick="bttPutToCart_Click" /></td>
</tr>
</table>
</ItemTemplate>
点击开Button 空间响应事件
1 protected void bttPutToCart_Click(object sender, EventArgs e)
2 {
3 Button bt = sender as Button;
4 int myIndex = ((DataListItem)bt.NamingContainer).ItemIndex;
5 Label lblid = bt.FindControl("lblId") as Label;
6 Label lbname = bt.FindControl("lblProduct_Name") as Label;
7 Label lbprice = bt.FindControl("lblPrice") as Label;
8 int id = int.Parse(lblid.Text);
9 string name = lbname.Text;
10 decimal price = decimal.Parse(lbprice.Text);
11 Profile.shopcart.AddItem(id, name, price);
12 Response.Redirect("../goods/Shop_car.aspx");
13 Label4.Text = name;
14
15
16 }
浙公网安备 33010602011771号