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:
qGetSearchResul ts:
SELECT
Adverts.AdvertI D,
Location.Locati on,
Jobtitle.JobTit le,
Speciality.Spec iality FROM (((Adverts
INNER JOIN Employer ON Adverts.Employe rID = Employer.Employ erID)
INNER JOIN Jobtitle ON Adverts.JobTitl eID = Jobtitle.JobTit leID)
INNER JOIN Location ON Employer.Locati onID = Location.Locati onID)
INNER JOIN Speciality ON Adverts.Special ityID = Speciality.Spec ialityID
WHERE
(@JobTitleID IS NULL OR Adverts.JobTitl eID = @JobTitleID)
AND (@JobTitleID IS NULL OR Adverts.JobTitl eID = @JobTitleID)
AND (@SpecialityID IS NULL OR Adverts.Special ityID = @SpecialityID)
AND (@LocationID IS NULL OR Employer.Locati onID = @LocationID)
AND (@KeyWords IS NULL OR Adverts.InfoTex t LIKE '%' + @KeyWords + '%')
AND (((Adverts.Star tDate)<=GetDate ())
AND (Adverts.EndDat e)>=GetDate())
ORDER BY Location.Locati on
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="gvSearchRes ults" runat="server" AllowSorting="T rue"
AutoGenerateCol umns="False"
DataKeyNames="A dvertID" DataSourceID="d sSearchResults" >
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
<asp:BoundFie ld DataField="Adve rtID" HeaderText="Adv ertID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "AdvertID" />
<asp:BoundFie ld DataField="Loca tion" HeaderText="Loc ation"
SortExpression= "Location" />
<asp:BoundFie ld DataField="JobT itle" HeaderText="Job Title"
SortExpression= "JobTitle" />
<asp:BoundFie ld DataField="Spec iality" HeaderText="Spe ciality"
SortExpression= "Speciality " />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="dsSearchRes ults" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:xxxx %>"
SelectCommand=" qGetSearchResul ts" SelectCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:QueryStrin gParameter Name="JobTitleI D" QueryStringFiel d="JobTitleID "
Type="Int32" />
<asp:QueryStrin gParameter Name="Specialit yID"
QueryStringFiel d="SpecialityID " Type="Int32" />
<asp:QueryStrin gParameter Name="LocationI D" QueryStringFiel d="LocationID "
Type="Int32" />
<asp:QueryStrin gParameter Name="KeyWords" QueryStringFiel d="KeyWords"
Type="String" />
</SelectParameter s>
</asp:SqlDataSour ce>
If I navigate to the page using a URL and querystring like this:
searchResults.a spx?LocationID= &SpecialityID=& KeyWords=&JobTi tleID=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