problem with two gridviews and SelectedValue

B

Bart

Hi,

In each classroom there are computers.
i have a gridview which shows all classrooms (from table location.
i have a second gridview which should show all computers of the selected row
in gridview1 (from table pc).

Gridview1 is not a problem, but when clicking on any Select of gridview1,
gridview2 doesn't appear.
When i replace in the code below this:
SelectCommand="SELECT * FROM [pc] WHERE ([lokl] = @lok
by this:
SelectCommand="SELECT * FROM [pc] WHERE ([lokl] = '3-35'
it works (3-35 is an existing classroom number).

The two tables have a common field (lok).

Thanks for help
Bart

Here the code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:les4demotestConnectionString1 %>"
SelectCommand="SELECT * FROM [location]"></asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" DataKeyNames="loknr"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="loknr" HeaderText="loknr"
InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="lok" HeaderText="lok" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:les4demotestConnectionString1 %>"
SelectCommand="SELECT * FROM [pc] WHERE ([lokl] = @lok)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="lok"
PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<asp:GridView ID="GridView2" runat="server" DataKeyNames="pcnr"
DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="pcnr" HeaderText="pcnr"
InsertVisible="False" ReadOnly="True"/>
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="lok" HeaderText="lok"
SortExpression="lok" />
</Columns>
</asp:GridView>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top