在CheckBoxList中,将多个值从一个页面传递到另一个页面 [英] In CheckBoxList pass multiple values from one page to another page

查看:231
本文介绍了在CheckBoxList中,将多个值从一个页面传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CheckBoxList中将多个值从一个页面传递到另一个页面...

解决方案

您可以使用session来实现此目的

在第一页设置会话中

  //  创建要存储的列表。 
List< string> StrList = new List< string>();
// 遍历每个项目。
foreach (ListItem item in ChkBox.Items)
{
if (item.Selected)
{
// 如果选中该项目,将值添加到列表中。
StrList.Add(item.Value);
}
}
// 现在设置会话
session [ selectedStrList] = StrList;
// 重定向到其他页面
Response.Redirect( ... false );



然后在第二页的页面加载事件中收到会话列表

  if (!IsPostBack)
{
List< string> StrList = new List< string>();
if (session [ selectedStrList]!= null // 确认会话不为空
StrList =(List< string>)session [ selectedStrList]; // 将会话对象转换为字符串列表
}

< br $>
快乐编码!

:)


你创建了一个隐藏字段然后创建数组,当任何复选框被打结时,将其推送到在表单提交时,然后在隐藏字段中的数组strore并传递到另一个页面


您需要询问具体问题并提供详细信息以获取帮助。不可能确切地知道你想要做什么。



无论如何,这是你正在使用的ASP(服务器端)控件。这些值将传递到表单提交的下一页,而不会执行任何操作。

此控件

< asp:CheckBoxList ID = CheckBoxList1 runat = server ClientIDMode = 静态 >
< asp:ListItem 文字 = 1 < span class =code-keyword> = 1 / >
< asp:ListItem 文本 = 2 Value = 2 < span class =code-keyword> / >
< / asp:CheckBoxList >







只需访问它们



 CheckBoxList1.Items(i).Selected 


In CheckBoxList pass multiple values from one page to another page...

解决方案

you can use session for this
In first page set session

// Create the list to store.
        List<string> StrList = new List<string>();
        // Loop through each item.
        foreach (ListItem item in ChkBox.Items)
        {
            if (item.Selected)
            {
                // If the item is selected, add the value to the list.
                StrList.Add(item.Value);
            }
        }
// Now set session 
session["selectedStrList"] = StrList;
//Redirect to other page
Response.Redirect("...", false);


then recieve list from session in second page's page load event

if(!IsPostBack)
{
    List<string> StrList = new List<string>();
    if ( session["selectedStrList"] != null) //confirm session is not null
         StrList = (List<string>)session["selectedStrList"]; //cast session object to list of string
}


Happy Coding!
:)


you have create one hidden field then create array and when any checkbox is cheked then push it to in array when form submit then array strore in hidden field and pass to another page


You need to ask specific question with details to get help. It's not possible to know exactly what you are trying to do.

Anyway, this is the ASP (server side) control you are using. The values get passed to the next page on form submit, without you doing anything.

for this control

<asp:CheckBoxList ID="CheckBoxList1" runat="server" ClientIDMode="Static">
            <asp:ListItem Text="1" Value="1" />
            <asp:ListItem Text="2" Value="2" />
        </asp:CheckBoxList>




Just access them as

CheckBoxList1.Items(i).Selected


这篇关于在CheckBoxList中,将多个值从一个页面传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆