简体   繁体   中英

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

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, ie a static int that is looped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM