📄 datalisthandle.aspx
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="C#" runat="server">
SqlConnection myConnection;
void Page_Load(Object sender, EventArgs e) {
myConnection = new SqlConnection("server=(local);database=Northwind;Trusted_Connection=yes");
if (!Page.IsPostBack) {
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Products", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Products");
MyDataList.DataSource=ds.Tables["Products"].DefaultView;
MyDataList.DataBind();
}
}
void MyDataList_Select(Object sender, EventArgs e) {
int productID = (int)MyDataList.DataKeys[MyDataList.SelectedItem.ItemIndex];
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Products where ProductID = @ProductID" , myConnection);
myCommand.SelectCommand.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int, 4));
myCommand.SelectCommand.Parameters["@ProductID"].Value=productID;
DataSet ds = new DataSet();
myCommand.Fill(ds, "ProductDetails");
DataRowView rowview = ds.Tables["ProductDetails"].DefaultView[0];
DetailsSupplierID.Text = "<b>供应商编号: </b>" + rowview["SupplierID"].ToString() + "<br>";
DetailsProductID.Text = "<b>货品编号: </b>" + rowview["ProductID"].ToString() + "<br>";
DetailsQuantityPerUnit.Text = "<b>计量单位: </b>" + rowview["QuantityPerUnit"].ToString() + "<br>";
DetailsPrice.Text = "<b>单价: </b> $ " + rowview["UnitPrice"].ToString() + "<p>";
PurchaseLink.Text = "购买:"+ rowview["ProductName"];
PurchaseLink.NavigateUrl ="purchase.aspx?ProductID=" + rowview["ProductID"].ToString();
DetailsName.Text = rowview["ProductName"].ToString();
}
</script>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form runat="server">
<table width="100%">
<tr>
<td width="50%">
<ASP:DataList id="MyDataList"
OnSelectedIndexChanged="MyDataList_Select"
DataKeyField="ProductID"
runat="server">
<ItemTemplate>
<table cellpadding=10 style="font: 10pt verdana">
<tr>
<td> 货品名:
<asp:linkbutton CommandName="Select"
Text='<%# DataBinder.Eval(Container.DataItem,"ProductName")%>'
runat="server"/><br>
<b>单价:</b><%# DataBinder.Eval(Container.DataItem,"UnitPrice","$ {0}")%><br>
</td>
</tr>
</table>
</ItemTemplate>
</ASP:DataList>
</td>
<td valign="top" style="padding-top:15" width="50%">
<table cellpadding="5" width="100%" style="font: 10pt verdana">
<tr>
<td><img id="DetailsImage" visible="false" runat="server"></td>
<td valign="top" width="400">
<div style="font: 12pt verdana;color:darkred">
<i><b><asp:Label id="DetailsName" runat="server"/></i></b><br>
</div>
<asp:Label id="DetailsProductID" runat="server"/>
<asp:Label id="DetailsSupplierID" runat="server"/>
<asp:Label id="DetailsQuantityPerUnit" runat="server"/>
<asp:Label id="DetailsPrice" runat="server"/>
<asp:HyperLink id="PurchaseLink" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -