Gridview never shows data

P

Phil Johnson

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>

--
Regards,

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

Angel

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.
 
A

Angel

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.
 
P

Phil Johnson

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.

--
Regards,

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


Angel said:
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.





--
aaa


Phil Johnson said:
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>

--
Regards,

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

Angel

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
--
aaa


Phil Johnson said:
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.

--
Regards,

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


Angel said:
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.





--
aaa


Phil Johnson said:
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>

--
Regards,

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

Phil Johnson

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.

--
Regards,

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


Angel said:
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
--
aaa


Phil Johnson said:
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.

--
Regards,

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


Angel said:
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.





--
aaa


:

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>

--
Regards,

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

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top