Timeslot html table - How to get the checkbox values?
Hi, I'm new here and am not quite sure if this is the correct place to post. But I'm having difficulties with the issue below.
Let's say I have a timeslot table, with 3 time slot - full day, morning shift and afternoon shift. And then users are able to tick among these 3 shifts for Monday - Friday. Users are only allowed to tick one checkbox for each day. So how am I going to obtain which checkbox are checked for which day?
Do I give a unique ID to each checkbox? I think this would be too troublesome, but I have no idea how else too. Any suggestion?
If only one per day is allowable, use grouped Radio buttons instead. Assign each group its own name, then you simply use Request.Form("GroupName") to get the value (assuming for form method="post").
Thanks a lot for the replies. I decided to go with a repeater control instead. I will post what I did here, so anyone else might find it useful in the future. Please do not be too hard on me should you find it a bit too long winded. I'm still very new to asp. So here goes:
-- CODE BEHIND--
// here is where i load the control names
protected void Page_Init(object sender, EventArgs e)
{
rptOfficeVolTimeslot.ItemDataBound += new RepeaterItemEventHandler(rptOfficeVolTimeslot_ItemDataBound);
}
// to get the user input values from the repeater
// construct a class ,eg here, I have the Timeslot class, containing a Timeslot list
// the list is where I will store values from the repeater
public List<TimeSlot> GetDayTimeSlotList()
{
List<TimeSlot> lstTimeSlot = new List<TimeSlot>();
foreach (RepeaterItem rptItem in rptOfficeVolTimeslot.Items)
{
TimeSlot clsTimeSlot = new TimeSlot();
clsTimeSlot.DayValue = (rptItem.FindControl("hdnDayValue") as HiddenField).Value;
clsTimeSlot.Day = (rptItem.FindControl("litDayName") as Literal).Text;
clsTimeSlot.FullShift = (rptItem.FindControl("chkBoxFull") as CheckBox).Checked;
clsTimeSlot.MornShift = (rptItem.FindControl("chkBoxMorning") as CheckBox).Checked;
clsTimeSlot.NoonShift = (rptItem.FindControl("chkBoxNoon") as CheckBox).Checked;
// just in case you are having difficulties in constructing the class, here goes
public class TimeSlot
{
public string Day { get; set; }
public string DayValue { get; set; }
public bool FullShift { get; set; }
public bool MornShift { get; set; }
public bool NoonShift { get; set; }
// to loop through the list containing the user input
private void btnClick_Click(object sender, EventArgs e)
{
List<TimeSlot> timeSlotResult = GetDayTimeSlotList();
Bookmarks