求助:我按照教程做的,可是DataList不会显示
前台:
<asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333" >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#EFF3FB" />
<SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<table style="width:100%;">
<tr>
<td>
<%#Eval("title") %></td>
<td>
<%#Eval("adddate") %></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
后台:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindDataList();
}
}
private void BindDataList()
{
string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter dap = new SqlDataAdapter("select * from news", conn);
DataSet ds = new DataSet();
dap.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Close();
}
------解决方案--------------------
先输出ds看有没有数据啊