| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:datalist取消编辑状态
只看楼主 加入收藏
tokoyoshi
Rank: 2
等 级:论坛游民
帖 子:99
专家分:67
注 册:2009-10-24
结帖率:87.1%
收藏
已结贴  问题点数:20 回复次数:2 
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事件,请问到底为什么,谢谢,这是我全部的分
搜索更多相关主题的帖子: 状态 datalist 
2009-11-09 02:25
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:20 
又是asp的东西啊,不懂

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-11-09 11:02
tokoyoshi
Rank: 2
等 级:论坛游民
帖 子:99
专家分:67
注 册:2009-10-24
收藏
得分:0 
呵呵···你真幸运·我自己解决了·没人说话就给你分吧·
2009-11-09 15:15
快速回复:datalist取消编辑状态
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032619 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved