【Asp.Net从零开始】:创建主表格以及单击获取详细信息的数据显示图
2012-08-13 09:00 ATP_ 阅读(990) 评论(0) 编辑 收藏 举报主要使用确定了DataKeyNames属性,即可在第二个数据源控件上设置where操作
<form id="form1" runat="server"> <div> </div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AutoLotConnectionString %>" SelectCommand="SELECT [CustID], [FirstName] FROM [Customers]"> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustID" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField SelectText="详细信息" ShowSelectButton="True" /> <asp:BoundField DataField="CustID" HeaderText="CustID" ReadOnly="True" SortExpression="CustID" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:AutoLotConnectionString %>" SelectCommand="SELECT * FROM [Customers] WHERE ([CustID] = @CustID)"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="CustID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="CustID" DataSourceID="SqlDataSource2" Height="50px" Width="125px"> <Fields> <asp:BoundField DataField="CustID" HeaderText="CustID" ReadOnly="True" SortExpression="CustID" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> </Fields> </asp:DetailsView> </form>
2个SqlDataSource,1个GridView,1个DetailsView
给梦想一点时间