1
selectede我有一個gridview
在我所6 radionbuttons
。在提交按鈕單擊我需要確定哪些radiobutton
的grid
每一行中被選中。現在即時通訊使用下面的代碼:標識哪個單選按鈕是在GridViewRow
protected void btnSubmit_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("OrderID");
dt.Columns.Add("QuestionID");
dt.Columns.Add("Rating");
foreach (GridViewRow gr in grdSurvey.Rows)
{
DataRow dr = dt.NewRow();
dr["QuestionID"] = ((HiddenField)gr.FindControl("hfQuestionID")).Value;
dr["OrderID"] = ViewState["_ORDERID"].ToString();
if (((RadioButton)gr.FindControl("rbSD")).Checked)
{
dr["Rating"] = "1";
}
else if (((RadioButton)gr.FindControl("rbSD")).Checked)
{
dr["Rating"] = "2";
}
else if (((RadioButton)gr.FindControl("rbDS")).Checked)
{
dr["Rating"] = "3";
}
else if (((RadioButton)gr.FindControl("rbNAND")).Checked)
{
dr["Rating"] = "4";
}
else if (((RadioButton)gr.FindControl("rbAS")).Checked)
{
dr["Rating"] = "5";
}
else if (((RadioButton)gr.FindControl("rbSA")).Checked)
{
dr["Rating"] = "6";
}
else if (((RadioButton)gr.FindControl("rbNA")).Checked)
{
dr["Rating"] = "0";
}
dt.Rows.Add(dr);
}
int Res = InsertSurveyResponse(dt);
if (Res > 0)
{
Response.Write(Res + " Response Submitted.");
}
}
前端低於:
<div id="divForm" runat="server">
<table width="80%" style="text-align:center;">
<tr>
<td>Your feedback is important and we promise it will take less than a minute of your time. All you have to do is – read the questions below and select the rating that you feel best describes your experience with us.
</td>
</tr>
<tr>
<td>Kindly give us your feedback below
</td>
</tr>
<tr>
<td>
<asp:gridview id="grdSurvey" runat="server" autogeneratecolumns="false" clientidmode="static">
<Columns>
<asp:TemplateField HeaderText="Question">
<ItemTemplate>
<asp:HiddenField ID="hfQuestionID" runat="server" Value='<%#Eval("QuestionID") %>'></asp:HiddenField>
<asp:Label ID="lblQuestion" runat="server" Text='<%#Eval("Question") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Strongly Disagree">
<ItemTemplate>
<asp:RadioButton ID="rbSD" runat="server" GroupName="Survey" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disagree Somewhat">
<ItemTemplate>
<asp:RadioButton ID="rbDS" runat="server" GroupName="Survey" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Neither Agree nor disagree">
<ItemTemplate>
<asp:RadioButton ID="rbNAND" runat="server" GroupName="Survey" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agree Somewhat">
<ItemTemplate>
<asp:RadioButton ID="rbAS" runat="server" GroupName="Survey" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Strongly Agree">
<ItemTemplate>
<asp:RadioButton ID="rbSA" runat="server" GroupName="Survey" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Not applicable">
<ItemTemplate>
<asp:RadioButton ID="rbNA" runat="server" GroupName="Survey" Checked="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
我需要避免的if else我使用的上提交按鈕我也不能使用單選按鈕名單。請幫忙。我想要服務器端代碼。沒有jQuery或JavaScript。
利用交換機..案例而不是If..ElseIf .. – 2014-09-23 08:49:30