这几天的一个小成果

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

综合这几天所学到的东西,写了个小东西,算是个成果吧(注意:该例子中用到的数据库是AccessXP里的Northwind.mdb)

<%@ Import namespace="System.Data"%>

<%@ Import namespace="System.Data.OleDb"%>

<HTML>

<body>

<form runat="server">

<asp:dropdownlist id="mydls" OnSelectedIndexChanged="subListChange" AutoPostBack="True" Runat="server"></asp:dropdownlist><asp:datagrid id="mydg" runat="server" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"

BackColor="White" CellPadding="4">

<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>

<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>

<ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>

<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>

</asp:datagrid>

<br>

<asp:button id="mybt" onclick="mybt_click" Runat="server" BorderStyle="Ridge" ForeColor="LightBlue"

Text="Show All"></asp:button>

<asp:DataGrid ID="mydg2" Runat="server" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"

BackColor="White" CellPadding="3" Visible="False" GridLines="Horizontal">

<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>

<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>

<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>

<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>

<PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>

</asp:DataGrid></form>

<script language="vb" runat="server">

sub page_load(source as object,e as eventargs)

if not ispostback then

dim strConnection as string

dim dbName as string

dbName=server.mappath("db/Northwind.mdb")

strConnection="Provider=Microsoft.JET.OleDb.4.0;Data Source="&dbName

dim myConnection as OleDbConnection

myConnection=new OleDbConnection(strConnection)

dim strSQL as string

strSQL="SELECT * FROM 类别"

dim myCommand as OleDbCommand

myCommand=new OleDbCommand(strSQL,myConnection)

myConnection.Open()

mydls.DataSource=myCommand.ExecuteReader()

mydls.DataTextField="类别名称"

mydls.DataValueField="类别名称"

mydls.DataBind()

myConnection.Close()

strSQL="SELECT * FROM 类别"

myConnection.Open()

myCommand.CommandText=strSQL

mydg2.DataSource=myCommand.ExecuteReader()

mydg2.DataBind()

myConnection.Close()

end if

end sub

sub subListChange(S as Object,e as EventArgs)

dim strConnection as string

dim dbName as string

dbName=server.mappath("db/Northwind.mdb")

strConnection="Provider=Microsoft.JET.OleDb.4.0;Data Source="&dbName

dim myConnection as OleDbConnection

myConnection=new OleDbConnection(strConnection)

dim strSQL as string

strSQL="SELECT * FROM 类别 WHERE 类别名称='"&mydls.SelectedItem.Value+"'"

dim myCommand as OleDbCommand

myCommand=new OleDbCommand(strSQL,myConnection)

myConnection.Open()

mydg.DataSource=myCommand.ExecuteReader()

mydg.DataBind()

myConnection.Close()

end sub

sub mybt_click(sender as object,e as eventargs)

if mydg2.Visible=false then

mydg2.Visible=true

mybt.Text="Hide All"

else

mydg2.Visible=false

mybt.Text="Show All"

end if

end sub

</script>

</body>

</HTML>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航