我在做一个问卷调查功能,在页面B中有一个Repeater控件,其中嵌套有RadioButtonList控件。在选项中我随意选几个。这时候我会跳转到页面A中,然后再回到页面B。我想要之前选择的几个选项仍然是选定状态。想到要用Cache来做,我没使用过Cache,不知到在这种业务中如何实现?ASP.NETCacheRadiobuttonlistjavascript

解决方案 »

  1.   

    这种不适合用cache 是单个会话,不是整体域的
    适合cookie或session
    你就保存选中项索引或ID标识之类的 加载时判断选中
      

  2.   

    你A页面应该是有保存B页面选择的按钮吧! 
    那么返回的时候带回B页面的写入记录,在重新绑定。
      

  3.   

    哦 针对单个用户的会话不适合用cache!由于我将选中的数据都在前端js做的,如何写入cookie或session呢?
      

  4.   

    1\可以用层来显示隐藏来表现,这样就不存在cookie或session
    2\用Session记录选项,字符格式如下"1,1,3,5",然后可以用JS设置默认值var checklist="<%= Session["checklist"]==""?"":Session["checklist"].ToString() %>"
    var arycheck=checklist.split(",");
    jQuery(".table1 > tbody > tr").each(function (i, item) {
       jQuery(item).find("input[type='radio'][value='"+ arycheck[i] +"']").attr("checked",true);
       //或者jQuery(item).find("input[type='radio']").eq(arycheck[i]).attr("checked",true);})
      

  5.   

    又是你啊 呵呵!这个功能做的我头疼 tmd!用你这种方式的话,比如我有5个radiobuttonlist,我开始只选其中的两个,这时候arycheck[i] 和 jQuery(item).find 对不上了吧就
      

  6.   


    <%@ Page EnableEventValidation="false" ValidateRequest="false"  Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style>
        .label
        {
            text-align:center; width:600px;
        }
        .red
        {
            color:#ff0000;
        }
        </style>
         <script src="/js/jquery.js" charset="utf-8"></script>
         <script>
             jQuery(document).ready(function () {
                 var checklist = "1,1,2,3,4,1,5,1";
                 var arycheck = checklist.split(",");
                 jQuery(".table1 > tbody > tr").each(function (i, item) {
                     jQuery(item).find("input[type='radio'][value='" + arycheck[i] + "']").attr("checked", true);
                     //jQuery(item).find("input[type='radio']").eq(parseInt(arycheck[i]) - 1).attr("checked", true);             })
             });
             function checkForm() {
                 var _message = "";
                 var _obj;
                 jQuery(".red").removeClass("red")
                 jQuery(".table1 > tbody > tr").each(function (i, item) {
                     if (jQuery(item).find("input[type='radio']:checked").length <= 0) {
                         _obj = jQuery(item).find("input[type='radio']").eq(0);
                         _message += jQuery(item).find(".td1").eq(0).text() + "没有勾选 ";
                         jQuery(item).addClass("red");
                         //return false;
                     }
                 });
                 if (_message != "") {
                     alert(_message);
                     jQuery(_obj).focus();
                     return false;
                 }
                 return true;
             }
         </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <table class="table1">
        <tbody>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 1.1
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 1.2
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList4" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 1.3
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList5" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            </tbody>
        </table>
        <table class="table1">
        <tbody>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 2.1
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList2" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 2.2
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList6" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            </tbody>
        </table>
        <table class="table1">
        <tbody>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 3.1
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList3" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 3.2
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList7" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td class="td1">
                    <span style="color: #FF001E">*</span> 3.3
                </td>
                <td class="td2">
                    <span>标题1</span>
                </td>
                <td class="td3">
                    <asp:RadioButtonList ID="RadioButtonList8" RepeatDirection="Horizontal" runat="server"
                        CssClass="radio">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="4">4</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            </tbody>
        </table>
        <asp:GridView ID="GridView1" runat="server" EnableModelValidation="True">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" CancelImageUrl="images/answer_bg.gif" DeleteImageUrl="images/banner1.jpg" />
            </Columns>
        </asp:GridView>
        <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="False" />
        </form></body>
    </html>
      

  7.   

    这种方式是可以,不过你没明白我的意思。比方你开始只选了1.1、2.2、3.3这三道题,然后要回到上一页面做些操作,最后返回该页时。session中保存的只有“1.1、2.2、3.3”。这时候如何给对应的radiobuttonlist初始化选定值呢?这时候arycheck[i] 和 jQuery(item).find 对不上了吧就 
      

  8.   


    在点下一步前就对映好,不选也要留空
    function getCheckID(){
      var checklist="";
      jQuery(".table1 > tbody > tr").each(function (i, item) { 
      if (jQuery(item).find("input[type='radio']:checked").length <= 0){
        checklist+=","
      }
      else{
        checklist+=jQuery(item).find("input[type='radio']:checked").eq(0).val() + ","  }
      });
      jQuery("#hd").val(checklist.substring(0,checklist.length-1))
    }