I have a DropDownList that's databound to our SQL server with an ID, First Name, Last Name. I've then added a GridView and Configured the Data Source to this
SELECT [ID], [fName], [lName] FROM [cb1] WHERE ([ID] = @ID)
Basically what I want it to do is when someone selects the first name from the dropdown it will pop up with the ID, First Name, and Last Name in the GridView.
The Problem is, when it's loaded the DropDownList is empty and has no data, and the GridView is also missing.
Here is the markup.
<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>