10分!!救命!!!datalist绑定数据怎么显示不出来???
前台:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Def...
前台:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
</asp:DataList></div>
</form>
</body>
</html>
后台:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection Conn = new SqlConnection("Data Source=PC-200812111756\\SQLEXPRESS;Initial Catalog=teachSystemDB;User ID=sa;Password=123456");//双斜杠
Conn.Open();
string sql = "select * from comments";
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql, Conn);
adapter.Fill(ds, "comments");
this.DataList1.DataSource = ds.Tables["comments"].DefaultView;
this.DataList1.DataBind();
}
} 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
</asp:DataList></div>
</form>
</body>
</html>
后台:using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection Conn = new SqlConnection("Data Source=PC-200812111756\\SQLEXPRESS;Initial Catalog=teachSystemDB;User ID=sa;Password=123456");//双斜杠
Conn.Open();
string sql = "select * from comments";
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql, Conn);
adapter.Fill(ds, "comments");
this.DataList1.DataSource = ds.Tables["comments"].DefaultView;
this.DataList1.DataBind();
}
} 展开
4个回答
展开全部
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.selectcommand=new …command(sql,conn)
adapter.selectcommand=new …command(sql,conn)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
里边方上<%#EVal("你要绑定的字段名")%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看我的
<asp:datalist id="DataList1" runat="server" RepeatColumns="10" CellPadding="0" RepeatDirection="Horizontal">
<ItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" border="0">
<TR>
<TD height="25" width="60">
<asp:HyperLink id=HyperLink23 runat="server" ForeColor="#ffffff" NavigateUrl='<%# MakeUrl1(DataBinder.Eval(Container.DataItem, "lx_name")) %>'>
<%# MakeUrl2(DataBinder.Eval(Container, "DataItem.lx_name").ToString()) %>
</asp:HyperLink></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist>
==============================================
SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]);
string strSel1 = "select * from chanpin_lx where lx_s_id='0' ORDER BY px ASC";
DataSet MyDataSet = new DataSet();
SqlDataAdapter myCommand2 = new SqlDataAdapter(strSel1,MyConnection);
myCommand2.Fill(MyDataSet,"999");
this.DataList1.DataSource = MyDataSet;
this.DataList1.DataBind();
<asp:datalist id="DataList1" runat="server" RepeatColumns="10" CellPadding="0" RepeatDirection="Horizontal">
<ItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" border="0">
<TR>
<TD height="25" width="60">
<asp:HyperLink id=HyperLink23 runat="server" ForeColor="#ffffff" NavigateUrl='<%# MakeUrl1(DataBinder.Eval(Container.DataItem, "lx_name")) %>'>
<%# MakeUrl2(DataBinder.Eval(Container, "DataItem.lx_name").ToString()) %>
</asp:HyperLink></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist>
==============================================
SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]);
string strSel1 = "select * from chanpin_lx where lx_s_id='0' ORDER BY px ASC";
DataSet MyDataSet = new DataSet();
SqlDataAdapter myCommand2 = new SqlDataAdapter(strSel1,MyConnection);
myCommand2.Fill(MyDataSet,"999");
this.DataList1.DataSource = MyDataSet;
this.DataList1.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询