开发者

Dynamically generate multiple RadioButtonList and capture their values

I have a situation where I need to generate multiple sets of radio buttons. These radio buttons display One to Many relationship data.

I know how to get it to work with a workaround that I used back in Classic ASP days ... in which I essentially just spit out the HTML dynamically and keep track of my controls using systematic IDs. Which is nothing more then an Primary Key appended to a string constant i.e. String.Format("Dynamic_{0}", myChildRecordPKValue) so my HTML looks like this:

<!--First Group-->
<h1>Parent Record 1</h1>
<input id="Child_998" name="group_1" onclick="javascript:getValue(this)"/>First
<input id="Child_999" name="group_1" onclick="javascript:getValue(this)"/>Second
<input id="Child_1000" name="group_1" onclick="javascript:getValue(this)"/>Third

<!--Second Group-->
<h1>Parent Record 2</h1>
<input id="Child_4598" name="group_2" onclick="javascript:getValue(this)"/>First
<input id="Child_7632" name="group_2" onclick="javascript:getValue(this)"/>Second
<input id="Child_92" name="group_2" onclick="javascript:getValue(this)"/>Third

<!--Second Group-->
<h1>Parent Record 3</h1>
<input id="Child_556" name="group_3" onclick="javascript:getValue(this)"/>First
<input id="Child_786" name="group_3" onclick="javascript:getValue(this)"/>Second
<input id="Child_110" name="group_3" onclick="javascript:getValue(this)"/>Third

Note that I am using a javascript function which updates a hidden field with the selected value (Each parent record has a cor开发者_JAVA百科responding hidden field). So after making selection user will hit the submit button and I get my values using Request.Form[myHiddenField1] and so on ...

So, my question is ... is there a better "ASP.NET" way of solving this problem?


I would look at creating a composite server control.

http://msdn.microsoft.com/en-us/library/3257x3ea(v=VS.90).aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜