dimanche 17 février 2019

get the value of all the checked checkboxes on button click

I have a create a table in my .aspx file that looks like this:

enter image description here

Here is the code that does this:

<!-- code for generating the "add selected sessions" button -->
<table>
    <tr>
        <td><strong>Individual Sessions</strong></td>
        <td >
            <div class="addButton" style="text-align: center;">
                <asp:LinkButton ID="LinkButton2" runat="server" Text="Add Selected Sessions" OnClick="btnAddToCart_Click" />
            </div>
        </td>
    </tr>
</table>

<!-- add all the sessions for the user to select -->
<asp:Repeater ID="rptFeesSession" runat="server">
    <HeaderTemplate>
        <table >
    </HeaderTemplate>
    <ItemTemplate>
        <asp:HiddenField ID="hdnIsSession" runat="server" Value='<%#Eval("isSession")%>' />
        <tr runat="server" visible='<%# Eval("isSession")%>'>
            <td valign="top" colspan="2" style="position: relative;">
                <asp:HyperLink CssClass="siteColorFG popBtn" ID="hlFeeType" runat="server" Text='<%#Eval("title")%>' NavigateUrl="javascript:;"/>
            </td>
            <td valign="top">
                <div class="">
                    <asp:CheckBox ID="LinkButton3" CommandArgument='<%#Eval("id")%>'CssClass="checkB" OnClick="btnAddToCart_Click" runat="server" Text='<%#Eval("amount", "{0:C}")%>' />
                </div>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

In my code behind file i want to capture all the checkboxes that have been checked and their respective CommandArgument values. protected void btnAddToCart_Click(object sender, EventArgs e)

{
    using (MyEntities db = new MyEntities())
    {
        //button was clicked. fetch all the check boxes from the rptFeesSession repeater into an int[]


    }
}




Aucun commentaire:

Enregistrer un commentaire