[ÕªÒª]ÉÏÒ»ÀýÖо²Ì¬Ìî³äÑ¡Ôñ¿òµÄÖµ£¬µ«Õⲻ̫ÊʺÏÄÇЩֵÔÚÊý¾Ý¿âÖлá¸ü¸ÄµÄÇé¿ö¡£ÒòΪ select HtmlControl Ò²Ö§³Ö IEnumerable DataSource ÊôÐÔ£¬¿ÉÒÔת¶øʹÓÃÑ¡Ôñ²éѯ¶¯Ì¬Ìî³äÑ¡Ôñ¿ò£¬Õ⽫±£Ö¤Êý¾Ý¿âºÍÓû§½çÃæʼÖÕͬ²½¡£ÏÂÃæµÄʾÀý˵Ã÷´Ë¹ý³Ì¡£<%@ Import Na...
ÉÏÒ»ÀýÖо²Ì¬Ìî³äÑ¡Ôñ¿òµÄÖµ£¬µ«Õⲻ̫ÊʺÏÄÇЩֵÔÚÊý¾Ý¿âÖлá¸ü¸ÄµÄÇé¿ö¡£ÒòΪ select HtmlControl Ò²Ö§³Ö IEnumerable
DataSource ÊôÐÔ£¬¿ÉÒÔת¶øʹÓÃÑ¡Ôñ²éѯ¶¯Ì¬Ìî³äÑ¡Ôñ¿ò£¬Õ⽫±£Ö¤Êý¾Ý¿âºÍÓû§½çÃæʼÖÕͬ²½¡£ÏÂÃæµÄʾÀý˵Ã÷´Ë¹ý³Ì¡£
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
SqlConnection myConnection;
protected void Page_Load(Object Src, EventArgs E)
{
myConnection = new SqlConnection("user id=sa;password=;initial catalog=pubs;data source=jeff");
if (!IsPostBack)
{
SqlDataAdapter myCommand = new SqlDataAdapter("select distinct State from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "States");
MySelect.DataSource= ds.Tables["States"].DefaultView;
MySelect.DataBind();
}
}
public void GetAuthors_Click(Object sender, EventArgs E)
{
String selectCmd = "select * from Authors where state = @State";
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@State", SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@State"].Value = MySelect.Value;
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource= ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();
}
</script>
<body style="font: 10.5pt ËÎÌå">
<form runat="server">
<h3><font face="ËÎÌå">¶Ô DataGrid ¿Ø¼þµÄ¶¯Ì¬²ÎÊý»¯Ñ¡Ôñ</font></h3>
Ñ¡ÔñÖÝ:
<select id="MySelect" DataTextField="State" runat="server"/>
<input type="submit" OnServerClick="GetAuthors_Click" Value="»ñÈ¡×÷Õß" runat="server"/><p>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="ËÎÌå"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</form>
</body>
</html>
……