开始的时候在网上看了一些帖子,采用了OnItemDataBind();的方法 但是在内层的label控件上Text的数据不能绑定 出现的错误是找不到控件
后来用Relations方法
在内层的DataList 的DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'
错误是CS0246: The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?)但是我已经用了: using System.Data;为什么呢?请各位大虾解决下?
后来用Relations方法
在内层的DataList 的DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'
错误是CS0246: The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?)但是我已经用了: using System.Data;为什么呢?请各位大虾解决下?
解决方案 »
- backgroundWorker.CancelAsync取消操作
- C#的winform如何实现医疗系统里的各种表单?
- 传datetimepicker值给存储过程问题
- DataTable.select,hastTable,XML效率问题
- c# fileview 控件问题
- 自定义控件的属性改变不了
- Windows Forms应用程序,安装包能不能集成donnet安装包
- 谁有电子书 Direct 3D和XNA(C#语言版)
- 请教ShellExcute调用WinRar不能正常解压的问题
- 请问,能否通过编程改变文件的属性,如 ,只读,系统,隐藏等
- [求助]DataSet与DataTable的问题,请大家帮忙
- ComboBox自动筛选功能, 你实现过吗? 提出方案并有简单的代码一准结贴,决不骗人!
id parentid Board_Style_Name
1 0 1111
2 1 2222
3 1 3333
<%@ Page Language="C#" Debug="true" Src="Behind_Code/index2.cs" Inherits="Behind_index2.list2"%>
<div align="center">
<ASP:DataList id="MyDataList" Width="100%" RepeatColumns="1" runat="server" >
<ItemTemplate>
<asp:label ID="Board_ID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>' runat="server"></asp:label>
<TABLE class=tableBorder1 cellSpacing=1 cellPadding=0 align=center>
<TBODY>
<TR>
<TH id=TableTitleLink align=left colSpan=2 height=25> <IMG src="images/nofollow.gif" width="15" height="15" border=0>
<%# DataBinder.Eval(Container.DataItem, "Board_Style_Name")%>
</TH>
</TR>
<TR>
<TD class=tablebody1 align=middle width="100%">
<ASP:DataList id="MyDataList_Child" Width="100%" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' RepeatColumns="1" runat="server">
<ItemTemplate>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD class=tablebody1 align=middle width=46><img src="images/forum_nonews.gif" width="24" height="24">
</TD>
<TD width=1 bgColor=#d66565>
<TD class=tablebody1 vAlign=top width=*>
<TABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD class=tablebody1 width=*><%# Container.ItemIndex+1%>
<a href="Board_List.aspx?Board_ID=<%# DataBinder.Eval(Container.DataItem, "[\"ID\"]")%>"><FONT color=#000066>『<%# DataBinder.Eval(Container.DataItem, "[\"Board_Style_Name\"]")%>』</FONT></a>
</TD>
<TD class=tablebody1 align=middle width=40 rowSpan=2></TD>
<TD class=tablebody1 width=200 rowSpan=2>
<asp:label ID="Title" runat="server"></asp:label>
<BR> <asp:label ID="Author" runat="server"></asp:label>
<BR> <asp:label ID="Createtime" runat="server"></asp:label>
</TD></TR>
<TR>
<TD width=*> <FONT face=Arial><IMG src="images/Forum_readme.gif" width="10" height="10"align=middle>
<%# DataBinder.Eval(Container.DataItem, "[\"Board_Style_Content\"]")%>
</FONT>
</TD>
</TR>
<TR>
<TD class=tablebody2 width=* height=20>
版主:
</TD>
<TD class=tablebody2 align=middle width=40> </TD>
<TD class=tablebody2 vAlign=center width=200>
</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
</TBODY>
</TABLE>
</ItemTemplate>
</ASP:DataList>
</TD></TR>
</TBODY>
</TABLE><BR>
</ItemTemplate>
</ASP:DataList>
</div>后台cs:string sql_child="select * from Board_Style where parentid in (select id from Board_Style where parentid=0)";
//Response.Write(sql_child);
//Response.End();
string sql_parent="select * from Board_Style where parentid=0";
SqlDataAdapter mc= new SqlDataAdapter(sql_parent, myConnection);
DataSet ds = new DataSet();
mc.Fill(ds,"board_info"); //DataRowView dv=new DataRowView(ds.Tables["Board_info"]);
SqlDataAdapter mc2= new SqlDataAdapter(sql_child, myConnection);
mc2.Fill(ds,"board_child_info");
ds.Relations.Add("myrelation",ds.Tables["board_info"].Columns["id"],ds.Tables["board_child_info"].Columns["parentid"]);
MyDataList.DataSource=ds.Tables["board_info"].DefaultView;
MyDataList.DataBind();
<%@ Import namespace="System.Data"%>
现在问题得到了解决
to:Eddie005(♂) 暴赱 『零零伍』 (︶︵︶)
我还是不大明白 我在cs文件中已经引用了using System.Data;
为什么在前台还要加上呢》?现在给分了