2
Answers

Getting values from multiple radiobutttonlist on a single page using C#

Photo of jasonb Blought

jasonb Blought

13y
1.7k
1
I am writting an application using C# to flag out on work type whether it's been done onsite or offsite. I have programmaticaly desing the Datatable source. however I want to find a way of reading data from the SQl database and also being able to insert the values into database.  this my asp.net and HTML code
<td>
<asp:RadioButtonList ID="TuesdayAttendanceTypeRadioButtonList" runat="server" AutoPostBack="True">
<asp:ListItem Text="On site" Value="Onsite"></asp:ListItem>
<asp:ListItem Text="Off site" Value="Offsite"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RadioButtonList ID="WednesdayAttendanceTypeRadioButtonList" runat="server" AutoPostBack="True">
<asp:ListItem Text="On site" Value="Onsite"></asp:ListItem>
<asp:ListItem Text="Off site" Value="Offsite"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td><asp:RadioButtonList ID="ThursdayAttendanceTypeRadioButtonList" runat="server" AutoPostBack="True">
<asp:ListItem Text="On site" Value="Onsite"></asp:ListItem>
<asp:ListItem Text="Off site" Value="Offsite"></asp:ListItem>
</asp:RadioButtonList>
</td>












Answers (2)

0
Photo of jasonb Blought
NA 3 1.7k 13y
my asp.net page does not directly deal with its manipulation behind code file ( getting values from controls, checking ....), instead this is done in a different class. My problem is this ,  let say I have got 5 RadioButtonLists each with 2 ListItems. I want to be able to read the values of all or any items selected and save or update the values in the database as well ( also if a selection has been saved already, it should indicates so ). I am using Daset and Datatable.  these are what my methods do:

this.attendanceDataTable = new DataTable();

this.attendanceDataTable.Columns.Add("
MonAttendanceTypeRadioButtonList");
row["
MonAttendanceTypeRadioButtonList"] = this.GetRadioButtonListAttendanceTypeText(this.AttendanceTypeText, i);

private string
GetRadioButtonListAttendanceTypeText(string currentRadioButtonListTxt, int index)
{
try
{
AttendanceEntry entry = this.AttendanceEntries.GetAttendanceTypeTextEntry(currentRadioButtonListTxt, index);
if (entry != null)
{
return entry.AttendanceType.ToString();
}
}
catch
{
}
return string.Empty;
}



Get Attendances type From Rows


RadioButtonList ChoicesButtonList = new RadioButtonList();


string radiobutton = this.
GetRadioButtonValueFromAttendanceText((RadioButtonList)row["MonAttendanceTypeTextRadioButtonList"]);

private string
GetRadioButtonValueFromAttendanceText(RadioButtonList currTextSelected)
{
try
{
string text;
return text = currTextSelected.SelectedValue.ToString();
}
catch
{
return null;
}

}


Thanks

0
Photo of Satyapriya Nayak
NA 53k 8m 13y
Hi Jasonb,

Please elaborate it more.



Thanks