CoolDev2014
asked on
asp.net, checkbox
I hav
I have below codes to get a list of checkbox.
and now if a submit button is clicked,
I want to capture all of the CHECKED value in the checkbox.
How can I do that?
<asp:DataList CellPadding="4" CellSpacing="200"
DataKeyField="ItemID"
RepeatColumns="3" ID="costItems" runat="server"
>
<ItemTemplate>
<asp:Panel Width="250px" runat="server" ID="panelControl">
<asp:CheckBox TextAlign="Left" runat="server" ID="subItemCost" />
<asp:Label runat="server" ID="description" Text='<%# Eval("Description") %>'></asp:Label>
($<asp:Label runat="server" ID="cost" Text='<%# Eval("Cost") %>'></asp:Label>)
</asp:Panel>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="submit" CssClass="btn" Text="Book Now" onclick="submit_Click" />
I have below codes to get a list of checkbox.
and now if a submit button is clicked,
I want to capture all of the CHECKED value in the checkbox.
How can I do that?
<asp:DataList CellPadding="4" CellSpacing="200"
DataKeyField="ItemID"
RepeatColumns="3" ID="costItems" runat="server"
>
<ItemTemplate>
<asp:Panel Width="250px" runat="server" ID="panelControl">
<asp:CheckBox TextAlign="Left" runat="server" ID="subItemCost" />
<asp:Label runat="server" ID="description" Text='<%# Eval("Description") %>'></asp:Label>
($<asp:Label runat="server" ID="cost" Text='<%# Eval("Cost") %>'></asp:Label>)
</asp:Panel>
</ItemTemplate>
</asp:DataList>
<asp:Button runat="server" ID="submit" CssClass="btn" Text="Book Now" onclick="submit_Click" />
ASKER
Thank but not working. It always returns "FALSE" regardless of it is checked or unchecked.
in the Page_Load method, is there a check on whether the page is a postback or not?
(!Page.IsPostback){
//Populate DataList
}
ASKER
jeroenemans: the answer is no.
If you can post your codes, that will be very helpful.
If you can post your codes, that will be very helpful.
There's your problem. You're recreating the checkboxes before reading their checked-property.
Modify your code so it won't rebind on postback, and you're done.
Modify your code so it won't rebind on postback, and you're done.
ASKER
got it. I am able to get the information. But I got one more question if you don't mind.
i have database table below
id desc cost
1 tire 100
2 brake 200
so now i am able to use datalist and checkbox to read the list.
but now I need to capture the checked value in the checkbox and save them into
new table
so if first checkbox is checked, i want to record into the database. can you show me how to do that?
i have database table below
id desc cost
1 tire 100
2 brake 200
so now i am able to use datalist and checkbox to read the list.
but now I need to capture the checked value in the checkbox and save them into
new table
so if first checkbox is checked, i want to record into the database. can you show me how to do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can you please show me in codes? Thanks
You should be able to figure it out yourself by now.
ASKER
It is okay if you can't show me in codes. Thank you for your time to help me...but i can't give you points based on your comments you posted.
Yes you can. But you won't. Just like I won't do your work for you.
ASKER
ok thank you. We just wait for other experts willing to help more. Again. Thank you for your time and effort.
Please find below code.
this will help you,
Open in new window