1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
2 DataKeyNames="ID" DataSourceID="SqlDataSource1">
3 <Columns>
4 <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
5 ReadOnly="True" SortExpression="ID" />
6 <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
7 <asp:BoundField DataField="pwd" HeaderText="pwd" SortExpression="pwd" />
8 <asp:BoundField DataField="cls" HeaderText="cls" SortExpression="cls" />
9 <asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
10 </Columns>
11 </asp:GridView>
12
13 </div>
14 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
15 ConnectionString="<%$ ConnectionStrings:textCon %>"
16
17 SelectCommand="SELECT [ID], [name], [pwd], [cls], [age] FROM [member] WHERE [name] = @pa"
18 onselecting="SqlDataSource1_Selecting">
19 <SelectParameters>
20 <asp:Parameter Name="pa" Type="String"/>
21 </SelectParameters>
22 </asp:SqlDataSource>
23 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
24 DataSourceID="SqlDataSource2" DataTextField="name" DataValueField="name"
25 onselectedindexchanged="DropDownList1_SelectedIndexChanged">
26 </asp:DropDownList>
27 <asp:SqlDataSource ID="SqlDataSource2" runat="server"
28 ConnectionString="<%$ ConnectionStrings:textCon %>"
29 SelectCommand="SELECT [ID], [name] FROM [member]"></asp:SqlDataSource>
然后我在selecting事件中这样处理:
e.Command.Parameters["@pa"].Value = DropDownList1.SelectedValue;
可是不知道为什么gridview没有显示出来,好像是@pa参数没有值,不知道这是为什么?
SqlDataSource,了解中是应该不用写代码的吧,都是点下鼠标选几下就出来了。
我有一篇N年前刚学的文章:无代码之-SqlDataSource [其实是objectDataSource]
如果感兴趣,对于数据表的操作,还可以看一下我的开源框架:CYQ.Data 轻量数据层之路 框架开源系列 索引