http://dotnet.aspx.cc/ShowDetail.aspx?id=54F4C732-AAE2-4135-FB1B-7B4B613BAA33用上面的方法做一般的嵌套是可以的,可datalist中嵌套dropdownlist就报错,大家帮帮忙:下面的方法行不通:
<asp:DropDownList Runat="server" DataSource='<%# Ctype(Container.DataItem,System.Data.DataRowView).Row.GetChildRows("MyRelation") %>' DataTextField="field1" DataValueField="field2"></asp:DropDownList>

解决方案 »

  1.   

    DataSource='<%# Ctype(Container.DataItem,System.Data.DataRowView).Row.GetChildRows("MyRelation") %>'
    这儿要指定绑定字段的吧??
    DataSource='<%# Ctype(Container.DataItem("字段"),System.Data.DataRowView).Row.GetChildRows("MyRelation") %>'
      

  2.   

    your datatextfield/datavaluefield are not properties, consider to write a ItemDataBound event handler for your datalistSub YourDataList_ItemDataBound(...........)
    {
      if e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem then
         dim ddl as DropDownList = CType(e.Item.FindControl("YourDropDownListID"), DropDownList)
         for each dr as DataRow in CType(e.Item.DataItem,System.Data.DataRowView).Row.GetChildRows("MyRelation"))
    ddl.Items.Add(new ListItem(dr("field1").ToString(), dr("field2").ToString()))
         next
      end if
    End Subor an alternative is to use something like<asp:DropDownList Runat="server" DataSource='<%# GetView(Ctype(Container.DataItem,System.Data.DataRowView).Row) %>' DataTextField="field1" DataValueField="field2"></asp:DropDownList>
    function GetView(ByVal dr as DataRow) as DataView
      dim ds as DataSet = dr.Table.DataSet
      dim dv as DataView = new DataView(ds.Tables(1))
      dv.RowFilter = "SomeCOlumn='" + dr("SomeColumn").ToString() + "'"
      return dv
    end function