我要綁定多單與repeater.But我得到的一些binding.Please錯誤幫助多表綁定轉發<>
這份名單是父子名單。 我收到錯誤
類型的異常 'System.Web.HttpException' 發生在 System.Web.dll中
但在用戶代碼
其他信息沒有處理: DataBinding:'Questionm'不包含名爲'Answer'的屬性。
**code**
**class Name:**
public class Questionm
{
public int QID { get; set; }
public string Question { get; set; }
public int AnswerType { get; set; }
public List<ChildLayers> ChildLayers { get; set; }
public Questionm()
{
ChildLayers = new List<ChildLayers>();
}
}
public class ChildLayers
{
public int QuestionID { get; set; }
public string Answer { get; set; }
}
**ASPX.cs Code**
public void daya()
{
SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=Test;Integrated Security=True");
SqlCommand cmd = new SqlCommand(); //
cmd.CommandText = "selectdata";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable DT = new DataTable();
DT = ds.Tables["Table"];
DataTable DT1 = new DataTable();
DT1 = ds.Tables["Table1"];
IList<Questionm> data = ConvertDataTable<Questionm>(DT);
IList<ChildLayers> cdata = ConvertDataTable<ChildLayers>(DT1);
IList<Questionm> hierarcy = new List<Questionm>();
List<Questionm> dsfsadsad = new List<Questionm>();
foreach (var layer in data)
{
Questionm obj = new Questionm();
obj.QID = layer.QID;
obj.Question = layer.Question;
obj.AnswerType =layer.AnswerType;
var sublayers1 = cdata.Where(i => i.QuestionID == layer.QID && i.QuestionID != 0);
foreach (var sublayer in sublayers1)
{
ChildLayers obj1 = new ChildLayers();
obj1.Answer = sublayer.Answer;
obj1.QuestionID = sublayer.QuestionID;
obj.ChildLayers.Add(obj1);
}
hierarcy.Add(obj);
}
rptparent.DataSource = hierarcy;
rptparent.DataBind();
}
**.aspx code**
<asp:repeater id="rptparent" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>Question</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# ((Questionm)Container.DataItem).QID %>
</td>
<%# ((Questionm)Container.DataItem).Question %>
<asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("Answer") %>' />
<%--Answer Text='<%# Eval("FileName") %>'>--%>
</tr>
</ItemTemplate>
<FooterTemplate>
</table><br />
</FooterTemplate>
</asp:repeater></td></tr>
類型「System.Web.HttpException」的異常出現在System.Web.dll中,但在用戶代碼中
其他信息沒有處理:DataBinding:'Questionm'不包含名爲'Answer'的屬性。
'的eval(「答」)'試圖訪問'Answer'上'Questionm'類屬性上,但該類這就是爲什麼你收到此錯誤沒有這樣的屬性。你需要避免這種情況。你能告訴我們爲什麼你要訪問'Answer'屬性'Questionm'嗎? –