●救命呀!!DataGrid 有没有DataSource属性???? cori (纯洁的女流氓) :绝对没问题,你也不用那么激动啊,喊救命,我以为发生什么事故了呵呵 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 cori (纯洁的女流氓) 同志!可以。晚上有空吗 我的文件 你看一看:<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><html><script language="C#" runat="server"> SqlConnection myConnection; protected void Page_Load(Object sender, EventArgs e) { myConnection =new SqlConnection("data source=你的ip;user id=sa;password=;initial catalog=pubs"); if (!IsPostBack) BindGrid("au_id"); } protected void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e) { BindGrid(e.SortExpression); } public void BindGrid(String sortfield) { SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection); DataSet ds = new DataSet(); myCommand.Fill(ds, "Authors"); DataView Source = ds.Tables["Authors"].DefaultView; Source.Sort = sortfield; MyDataGrid.DataSource=Source; MyDataGrid.DataBind(); }</script><body> <h3><font face="Verdana">Sorting Data in a DataGrid Control</font></h3> <form runat="server"> <ASP:DataGrid id="MyDataGrid" runat="server" OnSortCommand="MyDataGrid_Sort" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding=3 CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AllowSorting="true" /> </form></body></html>在sql server上用在"你的ip"出改为你自己的ip 要是本机的sql server可以写localhostuser 为用户名password是密码这样就可以运行了 astreeview控件实现城市联动 学习asp.net 在asp.net中用C#连接数据库 如何获取字符串真实长度? asp.net生成全静态页面新闻系统的思路 中文乱码问题 组合控件多属性相关更改问题? 作图,保存。本地没有问题,但上传服务器后,出错了。为何? PostBack后是先执行Page_Load()还是..... 问个关于连接的问题 在VS.net2003中创建新WEB项目时遇到的问题 ASP.NET时尚编程百例中的一个例子中的几句话弄不懂是为什么?高手请进!!!
<%@ Import Namespace="System.Data.SqlClient" %><html>
<script language="C#" runat="server"> SqlConnection myConnection; protected void Page_Load(Object sender, EventArgs e)
{
myConnection =new SqlConnection("data source=你的ip;user id=sa;password=;initial catalog=pubs"); if (!IsPostBack)
BindGrid("au_id");
} protected void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e)
{
BindGrid(e.SortExpression);
} public void BindGrid(String sortfield)
{
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection); DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors"); DataView Source = ds.Tables["Authors"].DefaultView;
Source.Sort = sortfield; MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
}</script><body> <h3><font face="Verdana">Sorting Data in a DataGrid Control</font></h3> <form runat="server"> <ASP:DataGrid id="MyDataGrid" runat="server" OnSortCommand="MyDataGrid_Sort"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AllowSorting="true"
/> </form></body>
</html>
在sql server上用
在"你的ip"出改为你自己的ip 要是本机的sql server可以写localhost
user 为用户名
password是密码这样就可以运行了