如何以编程方式创建和使用复选框列表从ASP.NET? [英] How to programmatically create and use a list of checkboxes from ASP.NET?

查看:101
本文介绍了如何以编程方式创建和使用复选框列表从ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有东西表的页面,我需要让用户选择行处理。我已经想通了如何复选框列添加到表中,但我似乎无法弄清楚如何测试是否提交表单时,他们进行检查。如果他们是静态元素,我能够只是做检查 this.theCheckBox ,但他们programaticly产生的。

I have a page with a table of stuff and I need to allow the user to select rows to process. I've figured out how to add a column of check boxes to the table but I can't seem to figure out how to test if they are checked when the form is submitted. If they were static elements, I'd be able to just check do this.theCheckBox but they are programaticly generated.

此外,我不是很满意,我如何连接我的资料给他们(在有ID属性馅的话)。

Also I'm not very happy with how I'm attaching my data to them (by stuffing it in there ID property).

我不知道,如果是相关的,但我看着有点左右为难,因为我需要知道哪些创建的复选​​框的最后一次围绕的是我前检查可以重新运行创建它们的code。

I'm not sure if it's relevant but I'm looking at a bit of a catch-22 as I need to known which of the checkboxes that were created last time around were checked before I can re-run the code that created them.


编辑:
我发现一个几乎解决方案。通过设置的AutoPostBack 属性和的CheckedChanged 事件:

checkbox.AutoPostBack = false;
checkbox.CheckedChanged += new EventHandler(checkbox_CheckedChanged);

我可以得到code被叫做后回已更改​​任何复选框。然而,这有两个问题:

I can get code to be called on a post back for any check box that has changed. However this has two problems:


  • 的回调是经过加工后(或期间,我不知道)的Page_Load ,我需要利用这个信息

  • 回叫不叫了页面加载时进行了检查,仍然复选框。

  • The call back is processed after (or during, I'm not sure) Page_Load where I need to use this information
  • The call back is not called for check boxes that were checked when the page loaded and still are.


编辑2:

我最终什么事做了标记我所有的ID与一个已知preFIX,并在顶部馅这个的Form_Load

What I ended up doing was tagging all my ID's with a know prefix and stuffing this at the top of Form_Load:

foreach (string v in this.Request.Form.AllKeys)
{
    if (v.StartsWith(Prefix))
    {
        var data = v.Substring(Prefix.Length);
    }
}

一切似乎到后期运行。

everything else seems to run to late.

推荐答案

我最终什么事做了标记我所有的ID与一个已知preFIX和填充这个在顶部的Form_Load

What I ended up doing was tagging all my ID's with a know prefix and stuffing this at the top of Form_Load:

foreach (string v in this.Request.Form.AllKeys)
{
    if (v.StartsWith(Prefix))
    {
        var data = v.Substring(Prefix.Length);
    }
}

一切似乎到后期运行。

everything else seems to run to late.

这篇关于如何以编程方式创建和使用复选框列表从ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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