M
Mike
I'm having trouble getting a gridview to bind. I probably missing something
completely obvious and would appreciate any help on offer.
I'm passing parameters via querystring, and have created a stored proc as
follows:
qGetSearchResults:
SELECT
Adverts.AdvertID,
Location.Location,
Jobtitle.JobTitle,
Speciality.Speciality FROM (((Adverts
INNER JOIN Employer ON Adverts.EmployerID = Employer.EmployerID)
INNER JOIN Jobtitle ON Adverts.JobTitleID = Jobtitle.JobTitleID)
INNER JOIN Location ON Employer.LocationID = Location.LocationID)
INNER JOIN Speciality ON Adverts.SpecialityID = Speciality.SpecialityID
WHERE
(@JobTitleID IS NULL OR Adverts.JobTitleID = @JobTitleID)
AND (@JobTitleID IS NULL OR Adverts.JobTitleID = @JobTitleID)
AND (@SpecialityID IS NULL OR Adverts.SpecialityID = @SpecialityID)
AND (@LocationID IS NULL OR Employer.LocationID = @LocationID)
AND (@KeyWords IS NULL OR Adverts.InfoText LIKE '%' + @KeyWords + '%')
AND (((Adverts.StartDate)<=GetDate())
AND (Adverts.EndDate)>=GetDate())
ORDER BY Location.Location
I have verified this works as expected in the Query Designer.
On the page, I have placed a DataSource Control and a GridView. The code
for both is as follows:
<asp:GridView ID="gvSearchResults" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="AdvertID" DataSourceID="dsSearchResults">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="AdvertID" HeaderText="AdvertID"
InsertVisible="False"
ReadOnly="True" SortExpression="AdvertID" />
<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" />
<asp:BoundField DataField="JobTitle" HeaderText="JobTitle"
SortExpression="JobTitle" />
<asp:BoundField DataField="Speciality" HeaderText="Speciality"
SortExpression="Speciality" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsSearchResults" runat="server"
ConnectionString="<%$ ConnectionStrings:xxxx %>"
SelectCommand="qGetSearchResults" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="JobTitleID" QueryStringField="JobTitleID"
Type="Int32" />
<asp:QueryStringParameter Name="SpecialityID"
QueryStringField="SpecialityID" Type="Int32" />
<asp:QueryStringParameter Name="LocationID" QueryStringField="LocationID"
Type="Int32" />
<asp:QueryStringParameter Name="KeyWords" QueryStringField="KeyWords"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
If I navigate to the page using a URL and querystring like this:
searchResults.aspx?LocationID=&SpecialityID=&KeyWords=&JobTitleID=35
the GridView refuses to appear, despite the fact that executing the Stored
Proc in SQL Server gives me 10 results.
What have I missed?
Mike
completely obvious and would appreciate any help on offer.
I'm passing parameters via querystring, and have created a stored proc as
follows:
qGetSearchResults:
SELECT
Adverts.AdvertID,
Location.Location,
Jobtitle.JobTitle,
Speciality.Speciality FROM (((Adverts
INNER JOIN Employer ON Adverts.EmployerID = Employer.EmployerID)
INNER JOIN Jobtitle ON Adverts.JobTitleID = Jobtitle.JobTitleID)
INNER JOIN Location ON Employer.LocationID = Location.LocationID)
INNER JOIN Speciality ON Adverts.SpecialityID = Speciality.SpecialityID
WHERE
(@JobTitleID IS NULL OR Adverts.JobTitleID = @JobTitleID)
AND (@JobTitleID IS NULL OR Adverts.JobTitleID = @JobTitleID)
AND (@SpecialityID IS NULL OR Adverts.SpecialityID = @SpecialityID)
AND (@LocationID IS NULL OR Employer.LocationID = @LocationID)
AND (@KeyWords IS NULL OR Adverts.InfoText LIKE '%' + @KeyWords + '%')
AND (((Adverts.StartDate)<=GetDate())
AND (Adverts.EndDate)>=GetDate())
ORDER BY Location.Location
I have verified this works as expected in the Query Designer.
On the page, I have placed a DataSource Control and a GridView. The code
for both is as follows:
<asp:GridView ID="gvSearchResults" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="AdvertID" DataSourceID="dsSearchResults">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="AdvertID" HeaderText="AdvertID"
InsertVisible="False"
ReadOnly="True" SortExpression="AdvertID" />
<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" />
<asp:BoundField DataField="JobTitle" HeaderText="JobTitle"
SortExpression="JobTitle" />
<asp:BoundField DataField="Speciality" HeaderText="Speciality"
SortExpression="Speciality" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsSearchResults" runat="server"
ConnectionString="<%$ ConnectionStrings:xxxx %>"
SelectCommand="qGetSearchResults" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="JobTitleID" QueryStringField="JobTitleID"
Type="Int32" />
<asp:QueryStringParameter Name="SpecialityID"
QueryStringField="SpecialityID" Type="Int32" />
<asp:QueryStringParameter Name="LocationID" QueryStringField="LocationID"
Type="Int32" />
<asp:QueryStringParameter Name="KeyWords" QueryStringField="KeyWords"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
If I navigate to the page using a URL and querystring like this:
searchResults.aspx?LocationID=&SpecialityID=&KeyWords=&JobTitleID=35
the GridView refuses to appear, despite the fact that executing the Stored
Proc in SQL Server gives me 10 results.
What have I missed?
Mike