2017-10-04 71 views
1

我要绑定多单与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> 

现在我是个收到此错误 enter image description here

类型“System.Web.HttpException”的异常出现在System.Web.dll中,但在用户代码中

其他信息没有处理:DataBinding:'Questionm'不包含名为'Answer'的属性。

+0

'的eval(“答”)'试图访问'Answer'上'Questionm'类属性上,但该类这就是为什么你收到此错误没有这样的属性。你需要避免这种情况。你能告诉我们为什么你要访问'Answer'属性'Questionm'吗? –

回答

0

从例外情况可以清楚地看到,您正在访问数据源列表中的无效属性名称。属性名称'Answer'不存在于您的列表对象中。

问题没有“应答”属性。

编辑:正如你已经在Questionm类中声明了一个列表类型属性,你需要遍历这个类来访问'Answer'属性。

例子:

((Questionm)Container.DataItem).Question.ChildLayers[0].Answer 
+0

我已列出此公开列表 ChildLayers {get;组; }在Questionm class .so中应该可以访问子图层参数。 –

+0

分享你的代码和.aspx代码 –

+0

都已经分享。 –