Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Gridview never shows data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Johnson - 02 Feb 2008 13:36 GMT
Hi,

I have 2 gridviews on an asp.net 2.0 form.

When I click select on a row in the first grid, in the
GridView1_SelectedIndexChanged event I set the value of a textbox (with
visibility set to false) to a string representation of a guid before calling
databind on my second grid.

The second grid never shows any data though, in fact it does not even show
the headers on the page unless I change its datasource to return all records,
not just filtered for the one selected in the first grid.

I initally just used a select statement in the datasource with an object
form parameter which got the value from my hidden text box, but I changed
that now to use a stored procedure that takes a string parameter and converts
that to a GUID inside the stored procedure.

If I configure the datasource when I test the query (which is the stored
procedure) I enter the valid guid in the parameter prompt and it does return
the values I should get in the test results pane.

My Datasource is set up as below and the value in txtLocationID at the point
where I call DataBind (on both the datasource and the gridview) is correct:

       <asp:SqlDataSource ID="FIDS_AdPages" runat="server"
           ConnectionString="<%$ ConnectionStrings:FIDSConnectionString %>"
           SelectCommand="AdvertPage_ReturnForLocation"
           SelectCommandType="StoredProcedure">

           <SelectParameters>
               <asp:FormParameter FormField="txtLocationID"
Name="LocationID" Type="String" />
           </SelectParameters>

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

Angel - 02 Feb 2008 17:02 GMT
It does not appear to be too difficult?!

On a knee jerk reaction I fired up VS and drop a gridview and a
sqldatasource.  I used stuff that already exists in the Northwind database.  
(Take advantage of this you learn a lot this way.)  

I notice there was a store procedure called CustOrderHist with one parameter
so it parallel what you were doing closely.  I gave it a default fired up the
page and it worked with out a hitch.  

The declarative stuff:

   <div>
       <asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
           DataSourceID="SqlDataSource1">
           <Columns>
               <asp:BoundField DataField="ProductName"
HeaderText="ProductName"
                   SortExpression="ProductName" />
               <asp:BoundField DataField="Total" HeaderText="Total"
ReadOnly="True"
                   SortExpression="Total" />
           </Columns>
       </asp:GridView>
   </div>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server"
       ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
       SelectCommand="CustOrderHist" SelectCommandType="StoredProcedure">
       <SelectParameters>
           <asp:QueryStringParameter DefaultValue="ALFKI" Name="CustomerID"
               QueryStringField="custid" Type="String" />
       </SelectParameters>
   </asp:SqlDataSource>

If this does not help let me know I will take a closer look for you.

Signature

aaa

> Hi,
>
[quoted text clipped - 30 lines]
> Name="LocationID" Type="String" />
>             </SelectParameters>
Angel - 02 Feb 2008 18:07 GMT
Wow!  

I played a little more with what you were talking about and did ran accross
a similar problem.

I came up with an approach where you can use the grids alone and it will
work without the use of the textbox.  I could not get the textbox to work but
I have a hunch...  In the mean time this might work.

   <div>
       <table class="style1">
           <tr>
               <td>
                   <input id="txtCustid" type="hidden" runat="server"
value="ALFKI" />
               </td>
               <td>
                    </td>
           </tr>
           <tr>
               <td>
                   <asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False"
                       DataKeyNames="CustomerID"
DataSourceID="SqlDataSource2">
                       <Columns>
                           <asp:CommandField ShowSelectButton="True" />
                           <asp:BoundField DataField="CustomerID"
HeaderText="CustomerID" ReadOnly="True"
                               SortExpression="CustomerID" />
                           <asp:BoundField DataField="CompanyName"
HeaderText="CompanyName"
                               SortExpression="CompanyName" />
                       </Columns>
                   </asp:GridView>
                   <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                       ConnectionString="<%$
ConnectionStrings:NorthwindConnectionString %>"
                       SelectCommand="SELECT [CustomerID], [CompanyName]
FROM [Customers] ORDER BY [CompanyName]">
                   </asp:SqlDataSource>
               </td>
               <td valign="top">
       <asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
                       DataSourceID="SqlDataSource1">
           <Columns>
               <asp:BoundField DataField="ProductName"
HeaderText="ProductName"
                   SortExpression="ProductName" />
               <asp:BoundField DataField="Total" HeaderText="Total"
ReadOnly="True"
                   SortExpression="Total" />
           </Columns>
       </asp:GridView>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server"
       ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
       SelectCommand="CustOrderHist" SelectCommandType="StoredProcedure">
       <SelectParameters>
           <asp:ControlParameter ControlID="GridView2" DefaultValue="ALFKI"
               Name="CustomerID" PropertyName="SelectedValue" Type="String"
/>
       </SelectParameters>
   </asp:SqlDataSource>
               </td>
           </tr>
       </table>
   </div>

I had to make sure you had a datakey on the first table and added a select
command link button then used the wizard to bind datasource1 to the
selectedvalue of Gridview2 and that worked.  But the first time it did not
work even though I had manually selected datakey field.  I re-did it this
time let the wizard do it and it worked.  I could not see the difference!! I
will keep looking to see if I can spot why this worked only when I let the
wizard generate the datakeys.

I hate this declarative stuff.

Signature

aaa

> Hi,
>
[quoted text clipped - 30 lines]
> Name="LocationID" Type="String" />
>             </SelectParameters>
Phil Johnson - 02 Feb 2008 21:16 GMT
Thanks for the responses Angel.

In the meantime I've changed the way I'm doing this so the management of
that entity opens in a different window rather than as a detail of a larger
form.... I really wanted to get it working in some way so I can hit my
deadline.

Thanks for any time you've spent looking into this though.

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> Wow!  
>
[quoted text clipped - 109 lines]
> > Name="LocationID" Type="String" />
> >             </SelectParameters>
Angel - 02 Feb 2008 22:00 GMT
I am glad you took care of your issue and it was no bother. I enjoy playing
around specially when I am laid up with a bug and I hate tv so this is kinda
fun.  Yes I know what you are thinking... Get a Life :-)   what can I tell
you.  By the way I think I have the whole thing working not sure  100% but it
does work.  If you ever interested let me know.

Regards,
Angel
Signature

aaa

> Thanks for the responses Angel.
>
[quoted text clipped - 118 lines]
> > > Name="LocationID" Type="String" />
> > >             </SelectParameters>
Phil Johnson - 02 Feb 2008 22:40 GMT
Glad you enjoyed looking into it!

I am the same when I am not working to a deadline, problem solving can be fun.

Hope you get better soon and thanks again for your time.

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> I am glad you took care of your issue and it was no bother. I enjoy playing
> around specially when I am laid up with a bug and I hate tv so this is kinda
[quoted text clipped - 127 lines]
> > > > Name="LocationID" Type="String" />
> > > >             </SelectParameters>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.