我无法在listview ASP.NET中获得checkbox的值 [英] I can't get the value of checkbox in listview ASP.NET

查看:54
本文介绍了我无法在listview ASP.NET中获得checkbox的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的aspx代码:





this is my aspx code :


<asp:ListView ID="ListViewHRDFormIzin" runat="server" DataSourceID="SqlDataStaffHRDFormIzin" DataKeyNames ="STAFF_NIK" enableviewstate="false">
     <LayoutTemplate>
         <table id="dataTable" class="table table-bordered striped data" align="left">
             <thead style="background-color:#4877CF">
                 <!-- add checkbox -->
                 <th style="text-align:center; color:white">Check</th>
                 <th style="text-align:center; color:white">NIK</th>
             </thead>
             <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
         </table>
     </LayoutTemplate>
     <ItemTemplate>
         <tr>
             <td>
                 <asp:CheckBox ID="CheckBox1" runat="server"  />
             </td>
             <td style="text-align:center"><asp:Label ID="lbl" runat="server" Text='<%# Eval("STAFF_NIK")%>' ></asp:Label></td>
             <td style="text-align:center"><asp:LinkButton ID="lnkSelect" Text='DETAIL' CommandName="Select" runat="server" ><img src="img/detail.png" width="50px" height="50px" /></asp:LinkButton></td>
         </tr>
     </ItemTemplate>
     <EmptyDataTemplate>Data Izin Karyawan Tidak diketemukan</EmptyDataTemplate>
     <EmptyItemTemplate>Data Izin Karyawan Tidak diketemukan</EmptyItemTemplate>
 </asp:ListView>

 <asp:Button  ID="Button1"  visible="true" runat="server"
 Text="Get Data" class="btn btn-success" />





这是我处理aspx页面的vb类:





this is my vb class that handle the aspx page :

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'get data from chekced checkbox
    Dim ChkValue As New List(Of String)()
    For Each item As ListViewItem In ListViewHRDFormIzin.Items
        Dim ck As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
        If ck.Checked Then
            ChkValue.Add(DirectCast(item.FindControl("lbl"), Label).Text)
        End If
    Next
    For Each itms As String In ChkValue
        Response.Write("<script>alert('Value Selected: " + itms + "')</script>")
    Next

    Response.Write("<script>window.location.href='HRDFORMIZIN.aspx';</script>")

End Sub





我尝试了什么:



我尝试了类似的东西,把它绑定在Page_Load中更新相关Listview的数据,更改为使用和任何内容。但是当我点击button1时,它没有值显示。代码总是运行代码的结尾(引用homepage.aspx)我不知道因为我是vb.net的新手



What I have tried:

I have tried anything like, put the binding data of related Listview in Page_Load, change to use and anything. but still when i hit the button1, its no value to display. and the code always run the end of the code ( Reference to the homepage.aspx) i have no idea since i am new in vb.net

推荐答案

你的代码看起来对我好。我建议你调试你的代码,在Button的click事件中设置一个断点并进入代码。验证它是否进入 for-each 循环。如果没有,则ListView数据源为空。
Your code looks good to me. I would suggest you to debug your code, set a break-point at Button's click event and step into the code. Verify if it goes into your for-each loop. If it doesn't then your ListView datasource is empty.


这篇关于我无法在listview ASP.NET中获得checkbox的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆