asp:repeater中的复选框总是假的。如何解决?

时间:2015-04-28 21:53:44

标签: asp.net vb.net buttonclick asprepeater

我有asp:带复选框的Repeater和按钮点击事件我需要用复选框值更新数据库中的表。如果选中复选框,则应插入值' Y'和' N'如果不。现在我有一个问题,每当我点击按钮甚至是被检查的复选框时,即button_click事件中的condotion Checkbox.checked始终为false。这是因为回发吗?有任何想法吗?这是我的代码。

  <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
                      <asp:UpdatePanel ID="UP_docaccess" runat="server">
                 <ContentTemplate>


                      <table class="table table-hover" id="tbldocaccessroles">
        <asp:Repeater ID="rptDocAccessroles" runat="server" OnPreRender="rptDocAccessroles_PreRender" >


       <HeaderTemplate>
    <tr class="active" style="font-weight: bold">
              <th style="text-align:center" >
           Role
           </th>
     <th style="text-align:center">View Access</th>
     <th style="text-align:center">Upload Access</th>
    </tr>
           </HeaderTemplate> 
        <ItemTemplate>

                <tr>

                <td class="checkbox" style="text-align:center" >
             <%# Eval("DOC_ROLES")%>
                   <asp:HiddenField ID="hdndoc_roleseq"  runat="server" Value ='<%#Eval("ROLE_SEQ")%>' />  
                </td>
                 <td style="text-align:center" >
                      <asp:CheckBox ID="cb_viewaccess" runat="server"  />
                      <asp:HiddenField ID="hiddenviewaccess"  runat="server" Value ='<%#Eval("VIEW_ACCESS")%>' />

                </td>
                <td style="text-align:center" >
                     <asp:CheckBox ID="cb_uploadaccess" runat="server"  />
                      <asp:HiddenField ID="hiddenuploadaccess"  runat="server" Value ='<%#Eval("UPLOAD_ACCESS")%>' />

                </td>
                </tr>


    </ItemTemplate>


        </asp:Repeater>

                           </table> 
                     <asp:Button ID="btn_clickfordoc" style="display:none"  runat="server"  />
                 </ContentTemplate>
                 </asp:UpdatePanel>

<asp:Button ID="btn_update" class="btn btn-warning btn-s" OnClick="btn_update_Click" runat="server" Text="Update Access for Roles" />

*按钮点击事件

Protected Sub btn_update_Click(sender As Object, e As EventArgs)
        Dim viewaccess As String
        Dim uploadaccess As String
        Dim rolesequence As String
        For Each ritem As RepeaterItem In rptDocAccessroles.Items
            Dim checkboxforview As CheckBox = DirectCast(ritem.FindControl("cb_viewaccess"), CheckBox)
            Dim checkboxforupload As CheckBox = DirectCast(ritem.FindControl("cb_uploadaccess"), CheckBox)
            Dim hiddenroleseq As HiddenField = DirectCast(ritem.FindControl("hdndoc_roleseq"), HiddenField)
            rolesequence = hiddenroleseq.Value
            If checkboxforview.Checked Then
                viewaccess = "Y"
            Else
                viewaccess = "N"
            End If

            If checkboxforupload.Checked Then
                uploadaccess = "Y"
            Else
                uploadaccess = "N"
            End If

            objTimeSystem.updatedocroles(CInt(rolesequence), usrID.Text, datechg.Text, viewaccess, uploadaccess, strErrNo, strMesg)


        Next

    End Sub

0 个答案:

没有答案