DATALIST绑定不了数组中数据?
publicpartialclassdatalist嵌套:System.Web.UI.Page{publicclassString{privatestringname;p...
public partial class datalist嵌套 : System.Web.UI.Page
{
public class String
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
private string old;
public string Old
{
get { return old; }
set { old = value; }
}
public String(string name, string sex, string old)
{
name = "名字";
sex = "性别";
old = "年龄";
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<String> ListInfos = new List<String>();
this.DataList1.DataSource =ListInfos;
DataList1.DataBind();
}
protected string why = "希望不要只是我才能显示出来";
}
为什么什么显示也没有,谢谢高手指点。
前台代码是:
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("sex") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("old") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<%=why%>
</div>
</form> 展开
{
public class String
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
private string old;
public string Old
{
get { return old; }
set { old = value; }
}
public String(string name, string sex, string old)
{
name = "名字";
sex = "性别";
old = "年龄";
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<String> ListInfos = new List<String>();
this.DataList1.DataSource =ListInfos;
DataList1.DataBind();
}
protected string why = "希望不要只是我才能显示出来";
}
为什么什么显示也没有,谢谢高手指点。
前台代码是:
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("sex") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("old") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<%=why%>
</div>
</form> 展开
1个回答
展开全部
你的ListInfos里没有东西,你让他显示鬼啊
protected void Page_Load(object sender, EventArgs e)
{
List<String> ListInfos = new List<String>();
for (int i=0;i<10;i++){
ListInfos.Add(new String("姓名"+i.ToString(),"性别"+i.ToString(),"年龄"+i.ToString()));
}
this.DataList1.DataSource =ListInfos;
DataList1.DataBind();
}
我实在想不出你这么做是要干嘛?
protected void Page_Load(object sender, EventArgs e)
{
List<String> ListInfos = new List<String>();
for (int i=0;i<10;i++){
ListInfos.Add(new String("姓名"+i.ToString(),"性别"+i.ToString(),"年龄"+i.ToString()));
}
this.DataList1.DataSource =ListInfos;
DataList1.DataBind();
}
我实在想不出你这么做是要干嘛?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询