Asp.net的datalist
来源:百度知道 编辑:UC知道 时间:2024/09/23 14:24:19
{
if (!IsPostBack)
{
DataList1.DataSource= dv();
DataList1.DataBind();
}
}
public DataView dv()
{
string strcon =@"Data Source=JIE\HIGHBURY;Initial Catalog=db_CMS;Integrated Security=True";
SqlConnection con = new SqlConnection(strcon);
SqlDataAdapter da = new SqlDataAdapter("Select * From tb_power",con);
DataTable dt = new DataTable();
da.Fill(dt);
DataView d;
d = new DataView(dt);
return d;
}
代码如上,为什么不显示呢
public void GvProductsDataBind()
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Products;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from Products", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
this.gvProducts.DataSource = dt;
this.gvProducts.DataKeyNames = new string[] { "id" };
this.gvProducts.DataBind();
}
看这个
DataList1.DataSource= dv()改成
DataList1.DataSource= dv().ToTable();
真麻烦。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds=new DataSet();
ds=dv();
DataList1.DataSource= ds;
DataList1.DataBind();
}
}
public DataSet dv()
{