我正在尝试将选定的单选按钮值从html到服务器端,以便我可以将它们保存在数据库中我已经在php中做了类似的操作,不知道如何在asp.net / C#
<form runat="server" id='attendence_form' >
<table id="attendence_div" width="100%" align="center" cellpadding="2" cellspacing="2" border="0">
<tr align="left" style="background-color:#004080;color:White;">
<td>Student Name</td>
<td>Present</td>
<td>Absent</td>
<td>Leave</td>
</tr>
<tr>
<td>ANITHA S</td>
<td><input type="radio" name="Present0" value="Present"></td>
<td><input type="radio" name="Present0" value="Absent"></td>
<td><input type="radio" name="Present0" value="Leave"></td>
</tr>
<tr>
<td>ANITHA T C</td>
<td><input type="radio" name="Present1" value="Present"></td>
<td><input type="radio" name="Present1" value="Absent"></td>
<td><input type="radio" name="Present1" value="Leave"></td>
</tr>
<tr>
<td>BINDU K V</td>
<td><input type="radio" name="Present2" value="Present"></td>
<td><input type="radio" name="Present2" value="Absent"></td>
<td><input type="radio" name="Present2" value="Leave"></td>
</tr>
</table>
听到的是php代码,它通过ajax从用户端获取html表单值并插入我想在asp.net中使用相同的
$conn = new mysqli($servername, $username, $password, $dbname);
// ** insert data in to data base ** //
$sql = "INSERT INTO attendance_master (AttendanceDate) VALUES ";
// **hear the data or is calculated using student as a string the number of student names are passed the same number of data is inserted in to data base ** //
foreach($_GET['student'] as $i=>$student) {
// ** so the data is inserted in to data base ** //
$sql .= sprintf("%s ('%s')"
, ($i==0 ? '' : ',')
// ** data from Ajax ** //
, mysqli_real_escape_string($conn, trim($_GET['present'][$i]))
);
}
// ** on success full function ** //
if ($conn->query($sql)) {
// **can do any thing to recognise if the data is inserted if this gives the out put then the data is shorly inserted in to data base ** //
}
答案 0 :(得分:0)
如果是webforms项目,您应该使用
<asp:RadioButton id="someId" runat="server">
更新
要处理单击radiobutton的时间,您需要处理CheckedChanged事件。
someId.CheckedChanged += event_CheckedChanged;
private void event_CheckedChanged(Object sender, EventArgs e)
{
... do stuff...
}
答案 1 :(得分:0)
您可以尝试使用<asp: RadioButton id="" runat="server" >
。
在服务器端,您可以像这样检查“已检查”属性
if(radioBtn.Checked==true) {}