各位大侠,在下遇到一个问题,请各位帮忙一下,问题如下:我前台有这样一下几个控件:
<tr>
<td><input id="RadIndustry1" title="保险业" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="1" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_16">
保险业</label></td>
<td>
</td>
<td><input id="RadIndustry2" title="采矿/能源" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="2" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_9">
采矿/能源</label></td>
<td>
</td>
<td><input id="RadIndustry3" title="餐饮/宾馆" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="3" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_4">
餐饮/宾馆</label></td>
<td>
</td>
</tr>
后台代码为 string strIndustry = ds.Tables["MemberShip"].Rows[0]["memberjob"].ToString();
if (strIndustry != "0")
{
//if()
//{}
//string strControl = "RadIndustry" + strIndustry; //this.strControl.Checked = true;
}我想做到当 strIndustry的值等于前台控件value的值的时候,那么这个 radio就被选中,不知道这个代码怎么写?
请给为大侠告诉我一下,谢谢了
<tr>
<td><input id="RadIndustry1" title="保险业" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="1" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_16">
保险业</label></td>
<td>
</td>
<td><input id="RadIndustry2" title="采矿/能源" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="2" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_9">
采矿/能源</label></td>
<td>
</td>
<td><input id="RadIndustry3" title="餐饮/宾馆" runat="server" style="width: 24px; height: 24px" onclick="leap('' ,'');"
type="radio" value="3" name="Industry"></td>
<td>
<label class="Answer" for="mainform:_idJsp23:0:_idJsp26_4">
餐饮/宾馆</label></td>
<td>
</td>
</tr>
后台代码为 string strIndustry = ds.Tables["MemberShip"].Rows[0]["memberjob"].ToString();
if (strIndustry != "0")
{
//if()
//{}
//string strControl = "RadIndustry" + strIndustry; //this.strControl.Checked = true;
}我想做到当 strIndustry的值等于前台控件value的值的时候,那么这个 radio就被选中,不知道这个代码怎么写?
请给为大侠告诉我一下,谢谢了
解决方案 »
- Cookies 子网站问题。
- 求一个搜索的SQL语句。
- tree view 问题
- 有哪个高手能把http://wwwapps.ups.com/WebTracking/processRequest网址的数据拿出来
- 这个vb.net的函数涌c#怎么写.我是个新手.莫怪
- [求助]请问如何判断session值与Request值的大小关系?急!
- 如何将图片存入ACCESS数据库并生成缩略图?
- 删不完的文件,请高手来指点。
- .net网站发布到虚拟主机上出现配置错误
- Windows server 2008 R2 安装IIS和发布网站的出现的问题
- 为什么在winform可以在asp.net不行??
- 不显示删除回复显示所有回复显示星级回复显示得分回复 请问一个asp.net的锚点问题,着急。。在线等
不想这样可以提交后 用asp方式Request.Form【"id"】也行
所有就不能确定是哪个控件。除非用If去判断例如以下代码
string strEducation=ds.Tables["MemberShip"].Rows[0]["member_Educate"].ToString();
if (strEducation != "0")
{
//string strControls = "RadEducation" + strEducation;
//Response.Write("<script language='javascript'>document.getElementById('RadEducation" + strEducation + "').checked=checked;</script>"); if (strEducation == "1")
{
this.RadEducation1.Checked = true;
}
if (strEducation == "2")
{
this.RadEducation2.Checked = true;
}
if (strEducation == "3")
{
this.RadEducation3.Checked = true;
}
if (strEducation == "4")
{
this.RadEducation4.Checked = true;
}
if (strEducation == "5")
{
this.RadEducation5.Checked = true;
}
if (strEducation == "6")
{
this.RadEducation6.Checked = true;
}
if (strEducation == "7")
{
this.RadEducation7.Checked = true;
}
}可是这样判断太多了,太麻烦了,如果这个控件要是有100个,那就要用100个IF语句判断,不知道能不能有其他简单的方法??
如果你都是按照数字顺序下来的。用for循环就可以了
建议使用asp控件
if语句那个,
(1)可以使用switch case语句,可以减少点代码,并且用break;可以提高效率
(2)定义一个自定义函数,参数是数字1,2,3,4等等,void fun(int i){("RadEducation"+i).Checked = true;}大致这样,具体细节自己调试去吧,没时间说那些细节,在适当地方调用函数就可以了
void fun(int i){("RadEducation"+i).Checked = true会报错的,("RadEducation"+i).Checked 代码是错误的,我也遇到这样的问题解决不了!
<asp:DataList ID="myList" runat="server" RepeatDirection="Horizontal" epeatLayout="Flow"
SelectedIndex="0">
<ItemTemplate>
<tr>
<td align="center" style="width: 60px; height: 35px;">
<asp:RadioButton ID="radio" onclick="aa()" value='<%#myList.Items.Count%>' runat="server" />
</td> </tr>
</ItemTemplate>
</asp:DataList>
<SelectedItemTemplate>
<tr>
<td align="center" style="width: 60px; height: 35px;">
<% '初始化の場合、一番データを選択する If (hid1.Value = "" Or hid1.Value = "0") Then
%>
<asp:RadioButton ID="radio" Checked="true" onclick="aa()" value='<%#myList.Items.Count%>'
runat="server" />
<%
'受払一覧画面から先画面データを選択する
ElseIf (hid1.Value <> "" Or hid1.Value <> "0") Then
%>
<asp:RadioButton ID="RadioButton1" Checked="false" onclick="aa()" value='<%#myList.Items.Count%>'
runat="server" />
<%
Dim radApp As RadioButton
radApp = myList.Items(Integer.Parse(hid1.Value)).FindControl("radio")
radApp.Checked = True
%>
<%
End If
%>
</td>
<td style="width: 450px; height: 35px;">
<%#(Container.DataItem)("PROC_NAME")%>
</td>
</tr>
</SelectedItemTemplate>