DataList绑定了productid,productname,添加了<asp:LinkButton>列表示购买
当点击LinkButton时就购买productid的商品,然后进行操作
我的问题是:
如何判断所点击的LinkButton是在哪个productid上?
也就是如何得到这个productid?
多谢!

解决方案 »

  1.   

    http://community.csdn.net/Expert/ForumList_Search.asp?searchtype=2&bigclassid=52&smallclassid=5202&searchKeys=LinkButton&author=&tabletype=now&Submit2=%B6%D4%D1%A1%D4%F1%B5%C4%D0%A1%C0%E0%BD%F8%D0%D0%CB%D1%CB%F7
      

  2.   

    在linkbutton中使用commandargument传递productid
    <asp:LinkButton id="linkbutton" commandargument='<%# DataBinder.Eval(Container.DataItem, "productid") %>' runat="server" text="link" onclick="DoLink">
    </asp:LinkButton>
    ..
    public void DoLink(object sender, System.EventArgs e)
    {
    LinkButton d=(LinkButton)sender;
    string productid=d.CommandArgument;
    }
      

  3.   

    itemcommand里面有
    e.item.itemindex
      

  4.   

    ItemCommand 事件在单击 DataList 控件中的任一按钮时引发,并且在具有带自定义 CommandName 值的按钮控件时通常使用它
         void Item_Command(Object sender, DataListCommandEventArgs e) 
          {
            
             // Set the SelectedIndex property to select an item in the DataList.
             ItemsList.SelectedIndex = e.Item.ItemIndex;         // Rebind the data source to the DataList to refresh the control.
             ItemsList.DataSource = CreateDataSource();
             ItemsList.DataBind();      }
      

  5.   

    用模版
    LinkButton.text绑定productname
    LinkButton.CommandArgument绑定productidPrivate Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
    事件中处理商品购买
      

  6.   

    <asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="productid" DataNavigateUrlFormatString="popo.aspx?productid={0}DataTextField="MainProjecID"></asp:HyperLinkColumn>
    在popo.aspx页:
    string productid=Request.QueryString["productid"].ToString;