aspx文件:
<asp:Repeater ID="Repeater_sorular" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<div class="div_soru">
<div class="div_soru_wrapper">
<%#Eval("Subject")%>
<asp:RadioButtonList ID="RadioButtonList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "1" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
</asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList_secenekler" runat="server" Visible='<%# Eval("TypeId").ToString() == "2" %>'
DataSource='<%#Eval("Secenekler")%>' DataTextField='<%#Eval("OptionName")%>' DataValueField='<%#Eval("OptionId")%>'>
</asp:CheckBoxList>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
和代码隐藏:
SpAnketDataContext db = new SpAnketDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeaterSorular();
}
}
protected void ImageButton_kaydet_OnCommand(object source, CommandEventArgs e)
{
}
private void BindRepeaterSorular()
{
int anket_id = 3;
var sorular = from soru in db.TableSurveyQuestions
where soru.SurveyId == anket_id
select new
{
soru.TypeId,
soru.Subject,
soru.QuestionId,
soru.SurveyId,
soru.QueueNo,
SurveyTitle = soru.TableSurvey.Title,
TypeName = soru.TableSurveyQuestionType.TypeName,
Secenekler = from secenekler in soru.TableSurveyOptions
select new
{
secenekler.OptionId,
secenekler.OptionName,
secenekler.QuestionId,
}
};
Repeater_sorular.DataSource = sorular;
Repeater_sorular.DataBind();
}
我的问题:
我不能约束datavaluefield和datatextfiled。 如果我写了如上定义。 我得到这个errror。
DataBinding: '<>f__AnonymousType1`8[[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.IEnumerable`1[[<>f__AnonymousT...' does not contain a property with the name 'OptionName'.
我怎样才能绑定值和文本。
谢谢。