我有一个 DropDownList,它通过 ID、名字、姓氏数据绑定到我们的 SQL 服务器。然后我添加了一个 GridView 并将数据源配置到这个
从 [cb1] 选择 [ID]、[fName]、[lName] 在哪里([ID] = @ID)
基本上我想要它做的是当有人从下拉列表中选择名字时,它会在 GridView 中弹出 ID、名字和姓氏。
问题是,加载后 DropDownList 为空且没有数据,并且 GridView 也丢失了。
这是标记。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="fName" HeaderText="fName" SortExpression="fName" />
<asp:BoundField DataField="lName" HeaderText="lName" SortExpression="lName" />
</Columns>
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="ID" DataValueField="ID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:comboConnectionString1 %>"
DeleteCommand="DELETE FROM [cb1] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [cb1] ([fName], [lName]) VALUES (@fName, @lName)"
ProviderName="<%$ ConnectionStrings:comboConnectionString1.ProviderName %>"
SelectCommand="SELECT [ID], [fName], [lName] FROM [cb1] WHERE ([ID] = @ID)"
UpdateCommand="UPDATE [cb1] SET [fName] = @fName, [lName] = @lName WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="fName" Type="String" />
<asp:Parameter Name="lName" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="fName" Type="String" />
<asp:Parameter Name="lName" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</p>