开发者

How to change the id of control within the repeater dynamically (C# asp.net)?

开发者 https://www.devze.com 2023-01-23 00:52 出处:网络
I have linkbutton within the repeater. The ID of the repeater is \"lnkbtn\". I have a datatable containing a column called as \"Questionnumber\".

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")


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号