【发布时间】:2012-11-25 23:25:51
【问题描述】:
如何将绑定Html5 data- attribute 添加到使用绑定RadioButtonList 生成的项目中?
我的代码如下所示:
<asp:Repeater Id="QuestionList" ...>
<ItemTemplate>
<asp:RadioButtonList DataSource='<%# Eval("Answers") %>'
SelectedValue='<%# Eval("SelectedAnswerId") %>'
DataTextField="Answer"
DataValueField="AnswerId"
Tag='<%# Eval("QuestionId") %>' />
</ItemTemplate>
</asp:Repeater>
var List<Question> questions = GetQuestions();
QuestionList.DataSource = questions;
QuestionList.DataBind();
它绑定到如下所示的类结构:
public class Question
{
int QuestionId;
string Question;
List<Answer> Answers;
}
public class Answers
{
int AnswerId;
string Answer;
bool SomeFlag;
}
我需要在 UI 中添加SomeFlag 以供 jQuery 使用,因此最终结果是生成的每个项目应如下所示:
<input type="radio" data-flag="true" ... />
有没有办法为绑定RadioButtonList生成的输入对象添加一个html数据属性?
【问题讨论】:
标签: c# asp.net html radiobuttonlist