首页 新闻 会员 周边

关于listview批量更新

0
悬赏园豆:10 [待解决问题]

在listview中 , 如图所示!如何点击更新按钮 , 将checkbox为true的数据都更新 ?

问题补充:
后台:        
protected void btnUpdate_Click(object sender, EventArgs e)
        {
            foreach (ListViewDataItem item in lvProducts.Items)
            {
                CheckBox ck = item.FindControl("cbCheck") as CheckBox;
                if (ck.Checked)
                {
                    Response.Write("check<br/>");
                }
                else
                {
                    Response.Write("no check<br/>");
                }
            }
        }
前端:    
<asp:ListView ID="lvProducts" runat="server">
    <ItemTemplate>
    <table>
        <tr>
          <td width="50" ><asp:CheckBox ID="cbCheck"
          Checked='<%# Eval("IsCheck") %>' runat="server" /></td>      
          <td width="120" align="center"><%# Eval("Id")%></td>
          <td width="120" align="center"><%# Eval("Name")%></td>
          <td width="120" align="center"><%# Eval("Price")%></td>
        </tr>
     </table>
    </ItemTemplate>
    <LayoutTemplate>
      <table>
        <tr>
          <th width="50">Check</th>
          <th width="120">Id</th>
          <th width="120">Name</th>
          <th width="120">price</th>
        </tr>
        <tr Id="itemPlaceholder" runat="server"></tr>
      <table>
    </LayoutTemplate>
    <EmptyDataTemplate>
        <table >
            <tr>
                <td>
                    没有数据。</td>
            </tr>
         </table>    
    </EmptyDataTemplate>
    </asp:ListView>
    <asp:Button ID="btnUpdate" runat="server" Text="更 新" 
        onclick="btnUpdate_Click" />
前端已经选中了,但后台的ck.Checked还是为false;
Jeff.Zhong的主页 Jeff.Zhong | 初学一级 | 园豆:198
提问于:2012-06-07 12:00
< >
分享
所有回答(3)
0

你是哪里不会,是获取checkbox选中内容不会还是更新数据不会?

artwl | 园豆:16736 (专家六级) | 2012-06-07 14:08

已经补充了问题,可否再帮我看看!

支持(0) 反对(0) Jeff.Zhong | 园豆:198 (初学一级) | 2012-06-07 15:49
0
foreach(var item in listView1.Items){
 
var checkbox =(CheckBox)item.FindControl("checkBox1");
 
if(checkbox.Checked){
//checkbox为true才会进入这个里面,在这里面调用你更新的方法。
  }

}

http://stackoverflow.com/questions/4914505/check-value-of-checkboxes-inside-listview
悟行 | 园豆:12559 (专家六级) | 2012-06-07 14:15

已经将代码贴出,请指点!

支持(0) 反对(0) Jeff.Zhong | 园豆:198 (初学一级) | 2012-06-07 15:49
0
 1 protected void btnUpdate_Click(object sender, EventArgs e)
 2         {
 3             foreach (ListViewDataItem item in lvProducts.Items)
 4             {
 5                 CheckBox ck = item.FindControl("cbCheck") as CheckBox;
 6                 if (ck.Checked)
 7                 {
 8                     Response.Write("check<br/>");
 9                 }
10                 else
11                 {
12                     Response.Write("no check<br/>");
13                 }
14             }
15         }

这后台的代码没有错啊,有没有使用模板列?

无 影 | 园豆:59 (初学一级) | 2012-06-08 11:31
 <ItemTemplate>
    <table>
        <tr>
          <td width="50" ><asp:CheckBox ID="cbCheck"
          Checked='<%# Eval("IsCheck") %>' runat="server" /></td>      
          <td width="120" align="center"><%# Eval("Id")%></td>
          <td width="120" align="center"><%# Eval("Name")%></td>
          <td width="120" align="center"><%# Eval("Price")%></td>
        </tr>
     </table>
    </ItemTemplate>

是在ItemTemplate模版中,什么模版列?

支持(0) 反对(0) Jeff.Zhong | 园豆:198 (初学一级) | 2012-06-08 14:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册