<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        CellPadding="4" ForeColor="#333333" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging"
        Width="600px">
        <PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
            NextPageText="下一页" PageButtonCount="15" PreviousPageText="上一页" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <Columns>
        <asp:TemplateField HeaderText="选择">
        <ItemStyle HorizontalAlign="Center" />
        <ItemTemplate>
        <asp:CheckBox ID="checkbox" runat="server" />
        </ItemTemplate>
        </asp:TemplateField>
            <asp:ImageField DataImageUrlField="tupian" DataImageUrlFormatString="../shoptup/{0}"
                HeaderText="产品图片">
                <ControlStyle Height="45px" Width="60px" />
            </asp:ImageField>
            <asp:HyperLinkField DataNavigateUrlFields="shopid" DataNavigateUrlFormatString="xiangxi.aspx?id={0}"
                DataTextField="xinghao" HeaderText="型号" />
            <asp:BoundField DataField="pinpai" HeaderText="品牌" />
            <asp:BoundField DataField="pinming" HeaderText="品名" />
            <asp:BoundField DataField="zuitisheng" HeaderText="最大提升高度" />
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center"
            VerticalAlign="Middle" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
这是Gridview内镶嵌checkbox作为商品标记;当我点击下面的商品比较按钮时
<asp:ImageButton
                                ID="ImageButton4" runat="server" Height="19px" ImageUrl="~/imge/bijia.png" OnClick="ImageButton4_Click" />
实现选中商品详细参数比较;后台代码怎么做呢,请高手们写详细代码;被这事郁闷好几天了啊

解决方案 »

  1.   

    你选中了 然后点击比较 后台直接遍历 你所选择控件 然后获取到ID 来进行比较foreach   (GridViewRow   row   in   GridView1.Rows) 
                            { 
                                    CheckBox   cb   =   (CheckBox)row.FindControl( "CheckBox2 "); 
                                    if   (cb.Checked==true) 
                                    { 
                                    } 
                            }
      

  2.   

    需要遍历,用 row.Cell[index] 或者 row.FindCOntrol(id) 访问大概如下,
    Button1_Click
    {
    int num = 0;
    foreach(GridViewRow row in GridView1.Rows){
    CheckBox chk = row.FindControl("CheckBox1") as CheckBox;
    if(chk.Checked) {
    string s = row.Cells[10].Text; // 得到选中行的ID
    num += int.Parse(s);
    }
    }
    }
      

  3.   

    关注中,也在纠结这个功能的实现,不过用的是JSP、Struts之类~
      

  4.   

    最简单的方法,在前台搜集选中的checkbox的值var list = document.getElementById("gridviewid").getElementsByTagName("Input");
    var values= [];
    for(var i = 0;i<list.length;i++)
    {
        if(list[i].checked)
           values.push(list[i].value);
    }
    把values转成一个字符串,保存到hidden里面,提交 。
      

  5.   

    Button1_Click
    {
    int num = 0;
    foreach(GridViewRow row in GridView1.Rows){
    CheckBox chk = row.FindControl("CheckBox1") as CheckBox;
    if(chk.Checked) {
    string s = row.Cells[10].Text; // 得到选中行的ID
    num += int.Parse(s);
    }
    }
    }