Data Bound Radio Buttons
hi guys,
I am doing a class register on a website where i will generate a list of names of students from a database and alongside each name there will be three radio buttons labelled "Present", "Absent" and "Late".
Generating the list of names to come on the website is very easy, the problem is how do i connect the three radio buttons to the names so when for example the "present" radio button is checked for that student, it will register on the database that he is present on a specific date.
I can do it with fixed values, for example if there are fixed names of pupils i can always name the radio buttons and it's easy from there but the names are generated at random from a long list in the database.
----------------------------------------------------------------------------------------------------------------------
I've got 2 pages. one with the form on it and the second to do the "insert" into the database.
Here is the code for the 2 pages.
------------------------------------------------
page1.asp
------------------------------------------------
<table width="395" height="38" border="2" cellpadding="2" cellspacing="0" bordercolor="#111111" style="border-collapse: collapse">
<%
sql = "Select * from tblstudent order by StudentID";
rs=myconn.Execute(sql);
while (!rs.eof)
{
%><tr>
<td width="200" height="34"><div align="center"><span class="style2"><%=rs("StudentID")%></span></div>
<td width="200" class="style1"><span class="style2"><%=rs("Name")%></span>
<td width="200" class="style1"><div align="center"><span class="style2">
<input name="rbtnPresent" type="radio" value="<%=rs("StudentID")%>">
</span></div>
<td width="200" class="style1"><div align="center"><span class="style2">
<input name="rbtnAbsent" type="radio" value="<%=rs("StudentID")%>">
</span></div>
<td width="200" class="style1"><div align="center"><span class="style2">
<input name="rbtnLate" type="radio" value="<%=rs("StudentID")%>">
</span></div>
<%
rs.movenext();
}
rs.Close();
%>
</table>
------------------------------------------------
page2.asp
------------------------------------------------
<%
var StudentID = Request.form("StudentID");
var Present = Request.form("rbtnPresent");
var Absent = Request.form("rbtnAbsent");
var Late = Request.form("rbtnLate");
%>
<table width="395" height="140" border="2" cellpadding="2" cellspacing="0" bordercolor="#111111" style="border-collapse: collapse">
<%
sql = "insert into tblattend (StudentID, Present, Absent, Late) ";
sql = sql + " values ('" + StudentID + "', " + Present + ", " + Absent + ", " + Late + ");" ;
rs=myconn.Execute(sql);
%>
Record added! :)
</table>
----------------------------------------------------------------------------------------------------------------------
I have all the connections to the database correct, nothing wrong on that side, just the radio buttons part. you have the code anyway, try it out with a database with 5 names just to test it.
This is last resort, i hope you can help
Thanks
|