如何从 Request.form.Allkeys 读取值

发布于 2024-09-29 21:15:49 字数 210 浏览 1 评论 0原文

我现在在回发时使用 Literal 创建了复选框,我得到了在 Request.form.Allkeys 中选中的复选框。但是我不知道如何读取这些值,如何使用它们?我如何计算其中有多少个值以及如何在其中找到一些值示例我想查找 request.forum.allkey 是否包含 forumaName0 ..

谢谢你

I have checkboxes that I have created using Literal now on postback I get the checkboxes which are checked in the Request.form.Allkeys. However I don't know how to read those values how can I use them? how can I count how many values are in there and how can I find some values in there example I want to find if the request.forum.allkey contain forumaName0 ..

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深空失忆 2024-10-06 21:15:49

假设您的 aspx 页面中有这些复选框:

<input id="Checkbox1" type="checkbox" name="forumaName0" />
<input id="Checkbox2" type="checkbox" name="forumaName1" />
<input id="Checkbox3" type="checkbox" name="forumaName2" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

您应该能够遍历所有键并检查是否选中了所需的复选框:

protected void Button1_Click(object sender, EventArgs e)
{
    foreach (string key in Request.Form.AllKeys)
    {
        Response.Write(key + "<br />");
    }

    Response.Write("Contain forumaName0? - " + Request.Form.AllKeys.Contains("forumaName0"));
}

编辑 - 否决者的屏幕截图:
替代文本

Assuming you have these checkboxes in your aspx page:

<input id="Checkbox1" type="checkbox" name="forumaName0" />
<input id="Checkbox2" type="checkbox" name="forumaName1" />
<input id="Checkbox3" type="checkbox" name="forumaName2" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

You should be able to iterate through all the keys and check if the desired checkbox is checked:

protected void Button1_Click(object sender, EventArgs e)
{
    foreach (string key in Request.Form.AllKeys)
    {
        Response.Write(key + "<br />");
    }

    Response.Write("Contain forumaName0? - " + Request.Form.AllKeys.Contains("forumaName0"));
}

EDIT - Screenshot for downvoter:
alt text

爱你不解释 2024-10-06 21:15:49

关于 Lee Sy En 和 AsifQadri 提到的 Contains 方法,请快速仅供参考:如果您想使用它,请确保您的程序集引用中有 System.Linq (或上面屏幕截图中显示的任何其他 IEnumerable 扩展方法)。

A quick FYI, in regards to the Contains method mentioned by Lee Sy En and AsifQadri: make sure you have System.Linq in your assembly references if you want to use it (or any of the other IEnumerable extension methods shown in the screenshot above).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文