首页 新闻 搜索 专区 学院

如何遍历ListView的中的每个单元格

0
悬赏园豆:15 [已解决问题] 解决于 2015-09-07 10:36

这是我的代码

for(int i=0;i<Lv_Cart.Items.Count;i++)
        {
            ListViewItem item = Lv_Cart.Items[i];
            
        }

Lv_Cart是ListView的ID

但是我想用item.SubItem来遍历

但是item中没有SubItem这个属性

雷大叔的主页 雷大叔 | 初学一级 | 园豆:51
提问于:2015-09-06 11:32
< >
分享
最佳答案
0

能把绑定数据的代码粘出来吗?

收获园豆:15
火悬崖 | 菜鸟二级 |园豆:434 | 2015-09-06 13:36

前台

<asp:ListView runat="server" ID="Lv_Cart"
            ItemPlaceholderID="itemPlaceHolder" OnItemDataBound="Lv_CartDataBound">
            <LayoutTemplate>
                <table>
                    <tr>
                        <th>
                            商品编号
                        </th>
                        <th>
                            商品名称
                        </th>
                        <th>
                            单价
                        </th>
                        <th>
                            数量
                        </th>
                        <th>
                            删除
                        </th>
                    </tr>
                <div runat="server" id="itemPlaceHolder">

                </div>
                    </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <%#Eval("pro_id") %>
                    </td>
                    <td>
                        <%#Eval("pro_name")%>
                    </td>
                    <td>
                        <asp:Label runat=server ID="Lb_price" Text='<%#Eval("pro_price") %>'></asp:Label>
                    </td>
                    <td>
                        <input runat="server" id="input_reduce" type="button" value="+" />
                       <asp:TextBox runat=server ID="Tb_num" Text='<%#Eval("cart_pro_num") %>' ></asp:TextBox>
                        <input runat="server" id="input_plus" type="button" value="-" />
                    </td>
                    <td>
                        <asp:Button runat="server" Text="删除" ID="Btn_Delete" OnCommand="OnDeleting" CommandArgument='<%#Eval("pro_id") %>' />
                    </td>
                </tr>
            </ItemTemplate>
            <EmptyItemTemplate>
                您没有添加任何商品
            </EmptyItemTemplate>
            
        </asp:ListView>

后台

string name=((User)Session["user"]).UserName.ToString();
            DB database = new DB();
            database.getConnection();
            database.open();
            string str_cmd;
            str_cmd = "select T_SHOPCART.*,T_USER.*,T_PRO.* from T_SHOPCART inner join T_PRO on T_SHOPCART.cart_pro_id =T_PRO.pro_id inner join T_USER on T_SHOPCART.cart_user_name =T_USER.user_name where T_USER.user_name = '" + name + "'";
            DataSet Ds = database.getDataSet(str_cmd);
            //为ListView添加绑定
            Lv_Cart.DataSource = Ds;
            Lv_Cart.DataBind();
           
            database.close();

雷大叔 | 园豆:51 (初学一级) | 2015-09-06 15:02

@leiyahui: SubItem这个属性是winform中的,在webform中用item.FindControl(id)来获得控件的

火悬崖 | 园豆:434 (菜鸟二级) | 2015-09-07 08:57

@火悬崖: 恩恩,谢谢

雷大叔 | 园豆:51 (初学一级) | 2015-09-07 09:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册