Dumb Gridview Question

J

Jason Wilson

OK I'm obviously fairly new to ASP.NET 2.0. I've used gridviews in the
past but only for pages with static queries that happen onload.

Now I have pretty simple scenario and I think I've followed all the
examples I've been able to find, but I still don't get the gridview to
render:

* I have a form with some textboxes and dropdownlist and a submit
button
* I have sqldatasource that uses form parameters to call a stored
procedure that does my query
* I have a gridview that is bound to the sqldatasource

At runtime, I fill in some know values and submit the form. The page
postsback and then I just see the form and the data entered -- the
gridview never appears.

I've tried adding an event handler for the button onclick that calls
the sqldatasource.select method. Same result.

I know there is something simple that I must be missing.

Any help from the world?

Jason

Here's some abrievated code:

<form id=...>
....some form elements...
....<asp:button...>

<asp:GridView ID="gvSearch" runat="server" DataSourceID="sqlDSSearch"
AutoGenerateColumns="true" AllowPaging="True" AllowSorting="True"
CellPadding="4" ForeColor="#333333" GridLines="None">

....some style stuff...

</asp:GridView>

<asp:SqlDataSource ID="sqlDSSearch" runat="server"
ConnectionString="<%$ ConnectionStrings:csAutomatedBilling
%>"
SelectCommand="PR_Search"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:FormParameter FormField="txtAccession"
Name="Accession" Type="String"
ConvertEmptyStringToNull="true" />
.....some more form parameters...
Type="String" ConvertEmptyStringToNull="true" />
<asp:FormParameter FormField="ddlStatus" Name="Status"
Type="String" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:SqlDataSource>
</form>
 
J

Jason Wilson

I've also tried changing the form parameters to control parameters --
same result.
 
J

Jason Wilson

Ok -- I got it to work, but only by putting
CancelSelectOnNullParameter="false" in sqldatasource. Problem is now
that it renderes of page load before the form has been submitted. Any
ideas on how to make it only render on postback?
 
J

Jason Wilson

OK -- I got it to work, but I had to put
CancelSelectOnNullParameter="false" parameter in my sqldatasource.
Problem is now the sqldatasource and gridview do their thing before the
form has been submitted.

I've set the CancelSelectOnNullParameter="true" in the datasource and
then changed in back in the onload event handler if the page.IsPostBack
= "true" but this seems a little clunky -- is this what everyone else
is doing?

How come none of the examples I've seen seem to be doing this. I guess
it's because all the examples either have all of the controls empty or
none of them.

Jason
 

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

Top