各位大侠,在下遇到一个问题,请各位帮忙一下,问题如下:我前台有这样一下几个控件:
<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>
                                                                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>
                                                                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>
                                                                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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就被选中,不知道这个代码怎么写?
请给为大侠告诉我一下,谢谢了

解决方案 »

  1.   

    前台控件加个runat=server  然后后台就可以访问到this。控件id。value
    不想这样可以提交后  用asp方式Request.Form【"id"】也行
      

  2.   

    你可能理解错了,前台控件我已经加了runat=server ,问题是strIndustry值是一个不确定的值,
    所有就不能确定是哪个控件。除非用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语句判断,不知道能不能有其他简单的方法??
      

  3.   

    把RadEducation1 换成服务器控件的RadiobuttonList用组的形式,赋值就简单了
      

  4.   


    如果你都是按照数字顺序下来的。用for循环就可以了
      

  5.   

    开始的问题没看懂
    建议使用asp控件
    if语句那个,
    (1)可以使用switch   case语句,可以减少点代码,并且用break;可以提高效率
    (2)定义一个自定义函数,参数是数字1,2,3,4等等,void fun(int i){("RadEducation"+i).Checked = true;}大致这样,具体细节自己调试去吧,没时间说那些细节,在适当地方调用函数就可以了
      

  6.   


    void fun(int i){("RadEducation"+i).Checked = true会报错的,("RadEducation"+i).Checked 代码是错误的,我也遇到这样的问题解决不了!
      

  7.   

    是不是可以,把那些RADIOBUTTON,做在一个DATALIST里,不过在后台要绑定一定组数据
    <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>
      

  8.   


                        <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>