业务逻辑数据层SqlDataSourcesql的输入参数控件参数System.Web.UI.WebControls.GridView.SelectedValue...
生活随笔
收集整理的這篇文章主要介紹了
业务逻辑数据层SqlDataSourcesql的输入参数控件参数System.Web.UI.WebControls.GridView.SelectedValue...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前臺代碼
??1?<%@?Page?Language="C#"?AutoEventWireup="true"?CodeBehind="CH7_DemoForm008.aspx.cs"?%>??2?
??3?<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
??4?
??5?<html?xmlns="http://www.w3.org/1999/xhtml">
??6?<head?id="Head1"?runat="server">
??7?????<title>示范使用?GridView?控件作為參數的控件源</title>
??8?</head>
??9?<body>
?10?????<form?id="form1"?runat="server">
?11?????<div?style="text-align:?center">
?12?????????<a?target="_blank"?href="http://www.cnblogs.com/liminzhang">
?13?????????????<img?style="border:?0;"?alt=""?src="Images/CH7_DemoForm008_Banner.jpg"?
?14?????????????title="前往章立民研究室"?/></a>
?15?????????<hr?/>
?16?????????<asp:GridView?ID="GridView1"?runat="server"?AllowPaging="True"?AllowSorting="True"
?17?????????????AutoGenerateColumns="False"?BackColor="White"?BorderColor="#E7E7FF"?BorderStyle="None"
?18?????????????BorderWidth="1px"?CellPadding="3"?DataKeyNames="訂單號碼,客戶編號"?DataSourceID="SqlDataSource1"
?19?????????????GridLines="Horizontal"?PageSize="5"?SelectedIndex="0"?Width="473px">
?20?????????????<FooterStyle?BackColor="#B5C7DE"?ForeColor="#4A3C8C"?/>
?21?????????????<RowStyle?BackColor="#E7E7FF"?ForeColor="#4A3C8C"?/>
?22?????????????<Columns>
?23?????????????????<asp:CommandField?ShowSelectButton="True"?/>
?24?????????????????<asp:BoundField?DataField="客戶編號"?HeaderText="客戶編號"?ReadOnly="True"?SortExpression="客戶編號"?/>
?25?????????????????<asp:BoundField?DataField="公司名稱"?HeaderText="公司名稱"?SortExpression="公司名稱"?/>
?26?????????????????<asp:BoundField?DataField="訂單號碼"?HeaderText="訂單號碼"?InsertVisible="False"?ReadOnly="True"
?27?????????????????????SortExpression="訂單號碼"?/>
?28?????????????????<asp:BoundField?DataField="訂單日期"?DataFormatString="{0:d}"?HeaderText="訂單日期"?SortExpression="訂單日期"?/>
?29?????????????</Columns>
?30?????????????<PagerStyle?BackColor="#E7E7FF"?ForeColor="#4A3C8C"?HorizontalAlign="Right"?/>
?31?????????????<SelectedRowStyle?BackColor="#738A9C"?Font-Bold="True"?ForeColor="#F7F7F7"?/>
?32?????????????<HeaderStyle?BackColor="#4A3C8C"?Font-Bold="True"?ForeColor="#F7F7F7"?/>
?33?????????????<AlternatingRowStyle?BackColor="#F7F7F7"?/>
?34?????????</asp:GridView>
?35?????????<asp:SqlDataSource?ID="SqlDataSource1"?runat="server"?ConnectionString="<%$?ConnectionStrings:chtNorthwind?%>"
?36?????????????SelectCommand="SELECT?客戶.客戶編號,?客戶.公司名稱,?訂貨主檔.訂單號碼,?訂貨主檔.訂單日期?FROM?客戶?INNER?JOIN?訂貨主檔?ON?客戶.客戶編號?=?訂貨主檔.客戶編號?ORDER?BY?客戶.客戶編號,?訂貨主檔.訂單號碼">
?37?????????</asp:SqlDataSource>
?38?????????<hr?/>
?39?????????<asp:ListView?ID="ListView1"?runat="server"?DataKeyNames="產品編號,訂單號碼"?DataSourceID="SqlDataSource2">
?40?????????????<AlternatingItemTemplate>
?41?????????????????<tr?style="background-color:?#FFFFFF;?color:?#284775;">
?42?????????????????????<td>
?43?????????????????????????<asp:Label?ID="折扣Label"?runat="server"?Text='<%#?Eval("折扣")?%>'?/>
?44?????????????????????</td>
?45?????????????????????<td>
?46?????????????????????????<asp:Label?ID="數量Label"?runat="server"?Text='<%#?Eval("數量")?%>'?/>
?47?????????????????????</td>
?48?????????????????????<td>
?49?????????????????????????<asp:Label?ID="單價Label"?runat="server"?Text='<%#?Eval("單價")?%>'?/>
?50?????????????????????</td>
?51?????????????????????<td>
?52?????????????????????????<asp:Label?ID="產品編號Label"?runat="server"?Text='<%#?Eval("產品編號")?%>'?/>
?53?????????????????????</td>
?54?????????????????????<td>
?55?????????????????????????<asp:Label?ID="訂單號碼Label"?runat="server"?Text='<%#?Eval("訂單號碼")?%>'?/>
?56?????????????????????</td>
?57?????????????????????<td>
?58?????????????????????????<asp:Label?ID="訂購金額Label"?runat="server"?Text='<%#?Eval("訂購金額")?%>'?/>
?59?????????????????????</td>
?60?????????????????</tr>
?61?????????????</AlternatingItemTemplate>
?62?????????????<LayoutTemplate>
?63?????????????????<table?id="Table1"?runat="server">
?64?????????????????????<tr?id="Tr1"?runat="server">
?65?????????????????????????<td?id="Td1"?runat="server">
?66?????????????????????????????<table?id="itemPlaceholderContainer"?runat="server"?border="1"?style="background-color:?#FFFFFF;
?67?????????????????????????????????border-collapse:?collapse;?border-color:?#999999;?border-style:?none;?border-width:?1px;
?68?????????????????????????????????font-family:?Verdana,?Arial,?Helvetica,?sans-serif;">
?69?????????????????????????????????<tr?id="Tr2"?runat="server"?style="background-color:?#E0FFFF;?color:?#333333;">
?70?????????????????????????????????????<th?id="Th1"?runat="server">
?71?????????????????????????????????????????折扣
?72?????????????????????????????????????</th>
?73?????????????????????????????????????<th?id="Th2"?runat="server">
?74?????????????????????????????????????????數量
?75?????????????????????????????????????</th>
?76?????????????????????????????????????<th?id="Th3"?runat="server">
?77?????????????????????????????????????????單價
?78?????????????????????????????????????</th>
?79?????????????????????????????????????<th?id="Th4"?runat="server">
?80?????????????????????????????????????????產品編號
?81?????????????????????????????????????</th>
?82?????????????????????????????????????<th?id="Th5"?runat="server">
?83?????????????????????????????????????????訂單號碼
?84?????????????????????????????????????</th>
?85?????????????????????????????????????<th?id="Th6"?runat="server">
?86?????????????????????????????????????????訂購金額
?87?????????????????????????????????????</th>
?88?????????????????????????????????</tr>
?89?????????????????????????????????<tr?id="itemPlaceholder"?runat="server">
?90?????????????????????????????????</tr>
?91?????????????????????????????</table>
?92?????????????????????????</td>
?93?????????????????????</tr>
?94?????????????????????<tr?id="Tr3"?runat="server">
?95?????????????????????????<td?id="Td2"?runat="server"?style="text-align:?center;?background-color:?#5D7B9D;?font-family:?Verdana,?Arial,?Helvetica,?sans-serif;
?96?????????????????????????????color:?#FFFFFF">
?97?????????????????????????</td>
?98?????????????????????</tr>
?99?????????????????</table>
100?????????????</LayoutTemplate>
101?????????????<InsertItemTemplate>
102?????????????????<tr?style="">
103?????????????????????<td>
104?????????????????????????<asp:Button?ID="InsertButton"?runat="server"?CommandName="Insert"?Text="插入"?/>
105?????????????????????????<asp:Button?ID="CancelButton"?runat="server"?CommandName="Cancel"?Text="清除"?/>
106?????????????????????</td>
107?????????????????????<td>
108?????????????????????????<asp:TextBox?ID="折扣TextBox"?runat="server"?Text='<%#?Bind("折扣")?%>'?/>
109?????????????????????</td>
110?????????????????????<td>
111?????????????????????????<asp:TextBox?ID="數量TextBox"?runat="server"?Text='<%#?Bind("數量")?%>'?/>
112?????????????????????</td>
113?????????????????????<td>
114?????????????????????????<asp:TextBox?ID="單價TextBox"?runat="server"?Text='<%#?Bind("單價")?%>'?/>
115?????????????????????</td>
116?????????????????????<td>
117?????????????????????????<asp:TextBox?ID="產品編號TextBox"?runat="server"?Text='<%#?Bind("產品編號")?%>'?/>
118?????????????????????</td>
119?????????????????????<td>
120?????????????????????????<asp:TextBox?ID="訂單號碼TextBox"?runat="server"?Text='<%#?Bind("訂單號碼")?%>'?/>
121?????????????????????</td>
122?????????????????????<td>
123?????????????????????????<asp:TextBox?ID="訂購金額TextBox"?runat="server"?Text='<%#?Bind("訂購金額")?%>'?/>
124?????????????????????</td>
125?????????????????</tr>
126?????????????</InsertItemTemplate>
127?????????????<SelectedItemTemplate>
128?????????????????<tr?style="background-color:?#E2DED6;?font-weight:?bold;?color:?#333333;">
129?????????????????????<td>
130?????????????????????????<asp:Label?ID="折扣Label"?runat="server"?Text='<%#?Eval("折扣")?%>'?/>
131?????????????????????</td>
132?????????????????????<td>
133?????????????????????????<asp:Label?ID="數量Label"?runat="server"?Text='<%#?Eval("數量")?%>'?/>
134?????????????????????</td>
135?????????????????????<td>
136?????????????????????????<asp:Label?ID="單價Label"?runat="server"?Text='<%#?Eval("單價")?%>'?/>
137?????????????????????</td>
138?????????????????????<td>
139?????????????????????????<asp:Label?ID="產品編號Label"?runat="server"?Text='<%#?Eval("產品編號")?%>'?/>
140?????????????????????</td>
141?????????????????????<td>
142?????????????????????????<asp:Label?ID="訂單號碼Label"?runat="server"?Text='<%#?Eval("訂單號碼")?%>'?/>
143?????????????????????</td>
144?????????????????????<td>
145?????????????????????????<asp:Label?ID="訂購金額Label"?runat="server"?Text='<%#?Eval("訂購金額")?%>'?/>
146?????????????????????</td>
147?????????????????</tr>
148?????????????</SelectedItemTemplate>
149?????????????<EmptyDataTemplate>
150?????????????????<table?id="Table2"?runat="server"?style="background-color:?#FFFFFF;?border-collapse:?collapse;
151?????????????????????border-color:?#999999;?border-style:?none;?border-width:?1px;">
152?????????????????????<tr>
153?????????????????????????<td>
154?????????????????????????????未傳回資料。
155?????????????????????????</td>
156?????????????????????</tr>
157?????????????????</table>
158?????????????</EmptyDataTemplate>
159?????????????<EditItemTemplate>
160?????????????????<tr?style="background-color:?#999999;">
161?????????????????????<td>
162?????????????????????????<asp:Button?ID="UpdateButton"?runat="server"?CommandName="Update"?Text="更新"?/>
163?????????????????????????<asp:Button?ID="CancelButton"?runat="server"?CommandName="Cancel"?Text="取消"?/>
164?????????????????????</td>
165?????????????????????<td>
166?????????????????????????<asp:TextBox?ID="折扣TextBox"?runat="server"?Text='<%#?Bind("折扣")?%>'?/>
167?????????????????????</td>
168?????????????????????<td>
169?????????????????????????<asp:TextBox?ID="數量TextBox"?runat="server"?Text='<%#?Bind("數量")?%>'?/>
170?????????????????????</td>
171?????????????????????<td>
172?????????????????????????<asp:TextBox?ID="單價TextBox"?runat="server"?Text='<%#?Bind("單價")?%>'?/>
173?????????????????????</td>
174?????????????????????<td>
175?????????????????????????<asp:Label?ID="產品編號Label1"?runat="server"?Text='<%#?Eval("產品編號")?%>'?/>
176?????????????????????</td>
177?????????????????????<td>
178?????????????????????????<asp:Label?ID="訂單號碼Label1"?runat="server"?Text='<%#?Eval("訂單號碼")?%>'?/>
179?????????????????????</td>
180?????????????????????<td>
181?????????????????????????<asp:TextBox?ID="訂購金額TextBox"?runat="server"?Text='<%#?Bind("訂購金額")?%>'?/>
182?????????????????????</td>
183?????????????????</tr>
184?????????????</EditItemTemplate>
185?????????????<ItemTemplate>
186?????????????????<tr?style="background-color:?#E0FFFF;?color:?#333333;">
187?????????????????????<td>
188?????????????????????????<asp:Label?ID="折扣Label"?runat="server"?Text='<%#?Eval("折扣")?%>'?/>
189?????????????????????</td>
190?????????????????????<td>
191?????????????????????????<asp:Label?ID="數量Label"?runat="server"?Text='<%#?Eval("數量")?%>'?/>
192?????????????????????</td>
193?????????????????????<td>
194?????????????????????????<asp:Label?ID="單價Label"?runat="server"?Text='<%#?Eval("單價")?%>'?/>
195?????????????????????</td>
196?????????????????????<td>
197?????????????????????????<asp:Label?ID="產品編號Label"?runat="server"?Text='<%#?Eval("產品編號")?%>'?/>
198?????????????????????</td>
199?????????????????????<td>
200?????????????????????????<asp:Label?ID="訂單號碼Label"?runat="server"?Text='<%#?Eval("訂單號碼")?%>'?/>
201?????????????????????</td>
202?????????????????????<td>
203?????????????????????????<asp:Label?ID="訂購金額Label"?runat="server"?Text='<%#?Eval("訂購金額")?%>'?/>
204?????????????????????</td>
205?????????????????</tr>
206?????????????</ItemTemplate>
207?????????</asp:ListView>
208?????????<asp:SqlDataSource?ID="SqlDataSource2"?runat="server"?ConnectionString="<%$?ConnectionStrings:chtNorthwind?%>"
209?????????????SelectCommand="SELECT?折扣,?數量,?單價,?產品編號,?訂單號碼,?(單價?*?數量)?*?(1?-?折扣)?AS?訂購金額?FROM?訂貨明細?WHERE?(訂單號碼?=?@訂單號碼)">
210?????????????<SelectParameters>
211?????????????????<asp:ControlParameter?ControlID="GridView1"?Name="訂單號碼"?PropertyName="SelectedValue"
212?????????????????????Type="Int32"?/>
213?????????????</SelectParameters>
214?????????</asp:SqlDataSource>
215?????????<hr?/>
216?????</div>
217?????</form>
218?</body>
219?</html>
220?
221?
?請摒棄樣式的研究,語法的限制,專注于控件函數的觀點。
那便是:
讀取數據(sql語句)
{
? sql語句(輸入參數);
}
輸入參數便是,
?<asp:ControlParameter?ControlID="GridView1"?Name="訂單號碼"?PropertyName="SelectedValue" Type="Int32"?/>
轉載于:https://www.cnblogs.com/samwu/archive/2010/07/31/1789332.html
總結
以上是生活随笔為你收集整理的业务逻辑数据层SqlDataSourcesql的输入参数控件参数System.Web.UI.WebControls.GridView.SelectedValue...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下如何获取cpu的利用率
- 下一篇: 病毒周报(100301至100307)