如何动态更改中继器内的控件ID(C# asp.net)?

发布于 2024-09-30 05:46:36 字数 379 浏览 3 评论 0原文

我在中继器内有链接按钮。 中继器的ID是“lnkbtn”。

我有一个数据表,其中包含名为“Questionnumber”的列。

问题编号”(列)包含诸如1,2,3,16,24.....等记录。

我想动态设置链接按钮的 ID。该 id 必须与“问题编号”相对应。

如果我将链接按钮的 ID(在转发器内)设置为 ID='<%# Eval("Questionnumber") %>' ,当我打算将编码编写为 时,我会遇到问题>repeater1.Items[].Findcontrol("lnkbtn")

I have linkbutton within the repeater.
The ID of the repeater is "lnkbtn".

I have a datatable containing a column called as "Questionnumber".

The "Questionnumber"(column) contains records such as 1,2,3,16,24.....so on.

I want to set the ID of the linkbutton dynamically.This id must be respective to the "Questionnumber".

if i set ID of the linkbutton(within repeater) as ID='<%# Eval("Questionnumber") %>' , i face problem when i intend to write the coding as repeater1.Items[].Findcontrol("lnkbtn")

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

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

发布评论

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

评论(2

抱着落日 2024-10-07 05:46:36

为什么要将问题编号值放入链接按钮 id 中? (请注意,在中继器等模板化控件中,html id 无论如何都会有所不同)。如果您需要识别问题编号的链接按钮,那么链接按钮的 CommandArgument 属性将是正确的选择。

Why you want to put question number value into link button id? (Note that in templated controls such as repeater, html ids would be anyway different). If you need to identify linkbutton for question number then CommandArgument property of linkbutton would be a correct choice.

皇甫轩 2024-10-07 05:46:36

我已经为动态生成的控件执行了此操作。您可以为标签添加前缀,例如 LinkBut​​ton_X。您可以覆盖每个元素的 ondatabinding 并在那里设置 id,或者您可以将数据绑定语法与方法和静态种子生成器(即循环的静态 int)一起使用。

I've did this for dynamically generated controls. You can prefix a tag such as LinkButton_X. You can override the ondatabinding for each element and set the id there OR you could use the databinding syntax with a method and a static seed generator, i.e a static int that is looped.

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