Binding sqldatacontrol to gridview

C

Chris

I have two SQLDataControls on a page. The first pulls all the data from a
table and is then bound to a gridview. The second uses the selected value in
the gridview which is in turn bound to a formview. When I run the page no
binding takes place, I assume that's because I haven't selected the
gridview. When I select a link it does nothing. What am I doing wrong?

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:CodeTrackerConnectionString %>"
SelectCommand="SELECT [PageID], [Title], [Description], [Keywords],
FROM [tblPages]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:CodeTrackerConnectionString %>"
SelectCommand="SELECT [Title], [Description], [Keywords], [URL], [PageID]
FROM [tblPages] WHERE ([PageID] = @PageID)"<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="PageID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
 
P

PeterKellner

Make sure you have in your Gridview1 declaration:

datakeynames=[PageID]

This should happen automatically if your primary key of table tblPages is
set to PageID.

Chris said:
I have two SQLDataControls on a page. The first pulls all the data from a
table and is then bound to a gridview. The second uses the selected value
in the gridview which is in turn bound to a formview. When I run the page
no binding takes place, I assume that's because I haven't selected the
gridview. When I select a link it does nothing. What am I doing wrong?

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CodeTrackerConnectionString %>"
SelectCommand="SELECT [PageID], [Title], [Description], [Keywords],
FROM [tblPages]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CodeTrackerConnectionString %>"
SelectCommand="SELECT [Title], [Description], [Keywords], [URL], [PageID]
FROM [tblPages] WHERE ([PageID] = @PageID)"<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="PageID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
http:// FROM [tblPages]"> </asp:Sql...lectParameters> </asp:SqlDataSource> [/QUOTE][/QUOTE]
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top