我是新手
想把数据库中的一个字段读取出来放在datalist里显示,结果没有错误提示,但是datalist什么也显示不了,请教高手
前台
<asp:DataList id="issue" runat="server" Width="382px" Height="100px">
<ItemTemplate>
<IMG height="10" src="images/button1.gif" width="9"> <FONT class="text5">
<%# DataBinder.Eval(Container.DataItem,"news_title")%>
</FONT>
</ItemTemplate>
</asp:DataList></td>
后台:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace chunyu
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList issue;
//private static String ConnectionString="Data Source=chunyudata;uid=sa;pwd=123;database=chunyu";
private void Page_Load(object sender,System.EventArgs e)
{
if(!Page.IsPostBack)
{
DataListEvent();
}
}
private void InitializeComponent()
{
}
private void DataListEvent()
{
String ConnectionString="Data Source=MEDIA-2;uid=sa;pwd=123;database=chunyu";
SqlConnection myConnection=new SqlConnection(ConnectionString);
myConnection.Open();
String cmdText="Select news_title from news";
SqlCommand myCommand=new SqlCommand(cmdText,myConnection);
issue.DataSource=myCommand.ExecuteReader();
issue.DataBind();
myConnection.Close();
}