¡¡¡¡datagridÊý¾Ý·ÃÎÊÊÇÈκÎʵ¼ÊÓ¦ÓóÌÐòµÄºËÐIJ¿·Ö£¬¶ø ASP.NET ÌṩÁËÒ»Ì׷ḻµÄ¿Ø¼þ£¬ÕâЩ¿Ø¼þÓ빫¹²ÓïÑÔÔËÐпâÖÐÌṩµÄÍйÜÊý¾Ý·ÃÎÊ API ºÜºÃµØ¼¯³ÉÔÚÒ»Æð¡£´Ó½ñÌ쿪ʼÎÒÃǾÍÀ´Ñ§Ï°DataGridÊý¾Ý¿Ø¼þµÄʹÓá£
¡¡¡¡ÎªÁËʹҳÄܹ»·ÃÎÊÖ´ÐÐ SQL Êý¾Ý·ÃÎÊËùÐèµÄÀ࣬±ØÐ뽫 System.Data ºÍ System.Data.SqlClient ÃüÃû¿Õ¼äµ¼Èëµ½Ò³ÖС£
<% Import Namespace="System.Data" %>
<% Import Namespace="System.Data.SqlClient" %>
¡¡¡¡ÈôÒª¶Ô SQL Êý¾Ý¿âÖ´ÐÐÑ¡Ôñ²éѯ£¬Çë´´½¨ÓëÊý¾Ý¿âµÄ SqlConnection£¬´«µÝÁ¬½Ó×Ö·û´®£¬È»ºó¹¹Ôì°üº¬²éѯÓï¾äµÄ SqlCommand ¶ÔÏó,ÔÙ¹¹ÔìSqlDataReader¶ÔÏó¶ÁÊý¾Ý¡£ÈôÒªÈÃDataGrid°ó¶¨Êý¾Ý£¬ÔòÒª°ÑSqlDataReader¶ÔÏóµÄʵÀý¸³ÓèDataGridµÄDataSourceÊôÐÔ£¬È»ºó°ó¶¨Ëü¡£
´úÂëÈçÏ£º
ÔÚaspxÎļþÀï¼ÓÈëDataGrid¿Ø¼þ£¬ÐÞ¸ÄÊôÐÔÈçÏ£º
<h3><font face="ËÎÌå">DataGrid ¿Ø¼þµÄ¼òµ¥Ñ¡Ôñ</font></h3>
<ASP:DataGrid id="DataGrid1" runat="server" Width="700" BackColor="#ccccff" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="ËÎÌå" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" EnableViewState="false">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
</ASP:DataGrid>
ÔÚaspx.csÎļþÀï¼ÓÈëÏÂÃæ´úÂ룺
Ê×Ïȵ¼ÈëSystem.Data.SqlClientÃüÃû¿Õ¼ä£»
ÔÙ¼ÓÈëÏÂÃæ´úÂ룺
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection myConnection = new SqlConnection("user id=sa;password=;initial catalog=pubs;data source=jeff");
myConnection.Open();
SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection);
SqlDataReader dr = myCommand.ExecuteReader();
DataGrid1.DataSource=dr;
DataGrid1.DataBind();
myConnection.Close();
}
DataGridѧϰһ
80¿á¿áÍø 80kuku.com