执行回发并为动态创建的复选框列表项在服务器端添加项 [英] Do a PostBack and add the items server-side for dynamically created checkboxlist item

查看:69
本文介绍了执行回发并为动态创建的复选框列表项在服务器端添加项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我对如何为CheckBoxList进行回发感到有些疯狂.

Its driving me bit crazy on how to do a PostBack for CheckBoxList.

我有一个自动完成文本框,可触发Javascript(在选定的项目上),通过该文本框我可以使用资源中的Javascript appendChild元素将项目动态添加到复选框列表中:

I have an autocomplete textbox that triggers the Javascript (on an item selected) by which I'm adding items to checkboxlist dynamically using Javascript appendChild element from the resource:

https://stackoverflow.com/a/3184505/1426121

但是,正如用户在答案中告诉的那样,添加的项目在下一刻消失了,为此,我必须执行一个PostBack(由他们建议).同样,如答案的注释中所示,我需要在CheckBoxList中有一个 *静态列表项,该Javascript才能正常工作.所以这里我总结了这个问题.

But as told by the user in the answer, the added item disappears the very next moment, for which I have to do a PostBack (suggested by them). Also as in the comment for the answer, I need to have a *static listitem in the CheckBoxList for that Javascript to work. So here I'm summarizing the question.

  1. 我要以正确的方式生成CheckBoxList项吗?还是有其他方法?

  1. Am I going in the right way to generate a CheckBoxList item? Or is there any other way?

如果没有其他选择,

  • 如何对以上代码进行回发?
  • 如何摆脱 *静态列表项?还是有任何解决方法可以从一组动态生成的列表项中隐藏单个静态列表项?
  • how can I do the postback for the above code?
  • how can I get rid of the *static listitem? Or is there any workaround for hiding a single static listitem from a set of dynamically generated listitems?

推荐答案

我真愚蠢地在SO上搜索这个愚蠢的问题.这是答案.

I was so dumb for searching on SO for this silly question. Here is the answer.

或者还有其他方法吗?"

"Or is there any other way?"

  • 在需要具有复选框列表的地方创建一个contentplaceholder
  • 将自动完成文本框值存储在ontextchanged事件中.
  • 调用一种用于生成复选框列表并传递listitem属性的方法.

示例代码:

private void AddingDynamicCheckBoxList(string listitem_name, string listitem_value)
{ chkBxLst1.Items.Add(new ListItem(listitem_name, listitem_value)); }

这篇关于执行回发并为动态创建的复选框列表项在服务器端添加项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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