Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从会话中检索单选按钮列表_C#_Asp.net - Fatal编程技术网

C# 从会话中检索单选按钮列表

C# 从会话中检索单选按钮列表,c#,asp.net,C#,Asp.net,正在从会话中检索单选按钮列表选择。我有一个单选按钮列表。我想在返回页面时获得所选内容。radiobutton列表由字符串数组填充 if (!IsPostBack) { RadioButtonList1.SelectedIndex = (string)Session["selection"]; } 将所选内容添加到会话

正在从会话中检索单选按钮列表选择。我有一个单选按钮列表。我想在返回页面时获得所选内容。radiobutton列表由字符串数组填充

                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
将所选内容添加到会话

                  Session["selection"] = RadioButtonList1.SelectedIndex;
                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
页面加载

                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
不工作不确定为什么来自MSDN:

                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
获取或设置列表中选定项的最低顺序索引 名单

                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
试试这个:

                    if (!IsPostBack)
                    {
                    RadioButtonList1.SelectedIndex = (string)Session["selection"];
                    }
RadioButtonList1.SelectedIndex = Convert.ToInt32(Session["selection"]);