I have a Recipes db which is displayed in Recipes ListView that gives 13 rows of data. The Recipes db loads into Recipes ListView just fine and the Recipes db has a relational db named RecipesDirections. Each db has a primary key of "Recipes" and the RecipesDirections
has a fk to Recipes which is "Category". The Recipes ListView shows the first ten names of recipes from the Recipes db. I would like to click on the 1st name in the Recipes ListView and have a page open (I'm using DetailPage.aspx as this page) showing the
same recipe (which has ingredients and directions) from the RecipesDirections db.
DetailPage.aspx does show the ingredients and directions, for 10 recipes, in a ListView from the RecipesDirections db if opened in a browser.
My goal is to be able to click on recipe #1 or recipe #2, or recipe #10 on the Recipes ListView and have that recipe with ingredients and directions open in the DetailPage.aspx. Right now, regardless of the link I click (1 through 10) on the Recipes List
View, the DetailPage.aspx opens and displays only the 1st recipe of the RecipesDirections db.
Decker Dong, thank your for your response. I have already, withouth using ObjectDataSource, but rather with SqlDataSource and ListView done what your refenced page says to do. Perhaps my question was not clear.
I have a ListView with a list of products, say products 1 through 10.
I have another ListView with details about the 1 through 10 products on another ListView.
If I click on product 1 in the product (the first) ListView, details 1 through 10 show up on the details (the second) ListView.
What I don't know how to do and would like to be able to do, is click on product 1 on the first ListView, and only product 1 (not 1 through 10) show up on the second (Details) ListView.
Perhaps I am wrong, but I would think there would be some link format that would take me from product 1 to (only) detail 1.
Thanks for your help Decker Dong. In both databases, Category is the primary key and has a data type "int". What I'd like to do is click on Recipe 1 in AfricanRecipes.aspx and go to Ingredients and Directions for Recipe 1 (only) in Details.aspx, Recipe
5 to Ingredients 5 (only), etc.
The is AfricanRecipes.aspx which gives a ListView with ten different recipes per page:
This is the Details.aspx page which has a ListView which renders the Ingredients and Directions for the recipes (1 through 10) of the ListView of AfricanRecipes.aspx:
Decker, I appreciate your help. I am a newbie, and have spent well over 100 hours trying to find the solution to my problem. I think perhaps your last question is close to the solution but I am not sure. After making the above changes that you suggested,
the AfricanRecipes.aspx page did render the ListView, but when the link was click, the error message "....incorrect format" came up. From what you said, it would appear that the AfricanRecipe.aspx page does not know, via the "category" in the connection
string, where to go on the Detail.aspx page.
On both the AfricanRecipes.aspx ListView and the Details.aspx ListView, "Category" is the primary key in both dbs, with a database type "int" and both are 'non-nullable". The first row, first column, is "Category" on both dbs and is "1".
1. Can you give me the link format, which I assume would go in the AfricanRecipes.aspx.cs, which would take me to the first row of the db in the Details.aspx, and then to the subsequent rows as I click each decending link on the AfricanRecipes.aspx page?
The following is the code on the AfricanRecipes.aspx.cs:
public partial class AfricanRecipes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
You gave me the following to put into the Details.aspx page. Would the "categoryID" on this page have to be changed to the same as on the AfricanRecipes.aspx.cs?
<asp:SqlDataSource ID="AfricanRecipesDirectionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [AfricanRecipesDirections] where categoryId=@categoryid">
<SelectParameters>
<asp:QueryStringParameter Name="categoryid" QueryStringField="category" Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
Again, thank you very much for your help.
EarlDavis1
0 Points
8 Posts
SqlDataSource used with ListView
Nov 05, 2012 02:50 PM|LINK
I have a Recipes db which is displayed in Recipes ListView that gives 13 rows of data. The Recipes db loads into Recipes ListView just fine and the Recipes db has a relational db named RecipesDirections. Each db has a primary key of "Recipes" and the RecipesDirections has a fk to Recipes which is "Category". The Recipes ListView shows the first ten names of recipes from the Recipes db. I would like to click on the 1st name in the Recipes ListView and have a page open (I'm using DetailPage.aspx as this page) showing the same recipe (which has ingredients and directions) from the RecipesDirections db.
DetailPage.aspx does show the ingredients and directions, for 10 recipes, in a ListView from the RecipesDirections db if opened in a browser.
My goal is to be able to click on recipe #1 or recipe #2, or recipe #10 on the Recipes ListView and have that recipe with ingredients and directions open in the DetailPage.aspx. Right now, regardless of the link I click (1 through 10) on the Recipes List View, the DetailPage.aspx opens and displays only the 1st recipe of the RecipesDirections db.
I am using C+
Any help would be greatly appreciated.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource used with ListView
Nov 06, 2012 03:54 AM|LINK
Hi,
If you want to click one item and it will guide you to another page to show detailled information, you can refer:
http://msdn.microsoft.com/en-us/library/aa581793.aspx
EarlDavis1
0 Points
8 Posts
Re: SqlDataSource used with ListView
Nov 11, 2012 04:56 PM|LINK
Decker Dong, thank your for your response. I have already, withouth using ObjectDataSource, but rather with SqlDataSource and ListView done what your refenced page says to do. Perhaps my question was not clear.
I have a ListView with a list of products, say products 1 through 10.
I have another ListView with details about the 1 through 10 products on another ListView.
If I click on product 1 in the product (the first) ListView, details 1 through 10 show up on the details (the second) ListView.
What I don't know how to do and would like to be able to do, is click on product 1 on the first ListView, and only product 1 (not 1 through 10) show up on the second (Details) ListView.
Perhaps I am wrong, but I would think there would be some link format that would take me from product 1 to (only) detail 1.
Any help would be greatly appreciated.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource used with ListView
Nov 12, 2012 12:47 AM|LINK
Would you mind showing us your full codes (including aspx and cs ones)?
EarlDavis1
0 Points
8 Posts
Re: SqlDataSource used with ListView
Nov 12, 2012 02:39 PM|LINK
Thanks for your help Decker Dong. In both databases, Category is the primary key and has a data type "int". What I'd like to do is click on Recipe 1 in AfricanRecipes.aspx and go to Ingredients and Directions for Recipe 1 (only) in Details.aspx, Recipe 5 to Ingredients 5 (only), etc.
The is AfricanRecipes.aspx which gives a ListView with ten different recipes per page:
<asp:SqlDataSource ID="AfricanRecipesSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [AfricanRecipes]"></asp:SqlDataSource>
<asp:ListView ID="AfricanRecipesListView" runat="server" DataSourceID="AfricanRecipesSqlDataSource"
DataKeyNames="Category">
<itemtemplate>
<tr >
<td>
<asp:HyperLink id="hlDetails3" Text='<%# Eval ("Category") %>' font-size="13px" align="top" width="100px" height="15px" Runat="server" NavigateUrl='<%# GetUrl(Eval ("Category"), Eval ("Category"))%>' />
<asp:HyperLink id="hlDetails4" Text='<%# Eval ("Name") %>' font-size="13px" width="370px" height="15px" Runat="server"
NavigateUrl='<%# GetUrl(Eval ("Name"), Eval ("Name"))%>' />
</td>
</tr>
<tr>
<td >
<asp:Label ID="ReviewLabel" runat="server" Text='<%# Eval("Review") %>' width="100px"
height="15px" font-size="13px" />
<asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' width="370px"
height="40px" font-size="13px" />
</td>
<tr>
<td>
<itemseparatortemplate>
<hr width="490px" color="LightGrey" />
</itemseparatortemplate>
</td>
</tr>
</tr>
</itemtemplate>
<layouttemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="font-size:12px">
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</layouttemplate>
</asp:ListView>
</asp:Content>
This is the .cs for AfricanRecipes.aspx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AfricanRecipes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetUrl(object id, object category)
{
string url = "~/DetailPage.aspx?category=" + id.ToString() + "&category=" +
Server.UrlEncode(category.ToString());
return url;
}
}
This is the Details.aspx page which has a ListView which renders the Ingredients and Directions for the recipes (1 through 10) of the ListView of AfricanRecipes.aspx:
<asp:SqlDataSource ID="AfricanRecipesDirectionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [AfricanRecipesDirections]"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="AfricanRecipesDirectionsSqlDataSource"
DataKeyNames="Category">
<itemtemplate>
<tr>
<td>
<asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
</td>
<td>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
<tr>
<td width="150px" align="center"><p>Ingredients</p>
<asp:Label ID="IngredientOneLabel" runat="server"
Text='<%# Eval("IngredientOne") %>' /><br />
<asp:Label ID="IngredientTwoLabel" runat="server"
Text='<%# Eval("IngredientTwo") %>' /><br />
<asp:Label ID="IngredientThreeLabel" runat="server"
Text='<%# Eval("IngredientThree") %>' /><br />
<asp:Label ID="IngredientFourLabel" runat="server"
Text='<%# Eval("IngredientFour") %>' /><br />
<asp:Label ID="IngredientFiveLabel" runat="server"
Text='<%# Eval("IngredientFive") %>' /><br />
<asp:Label ID="IngredientSixLabel" runat="server"
Text='<%# Eval("IngredientSix") %>' /><br />
<asp:Label ID="IngredientSevenLabel" runat="server"
Text='<%# Eval("IngredientSeven") %>' /><br />
<asp:Label ID="IngredientEightLabel" runat="server"
Text='<%# Eval("IngredientEight") %>' /><br />
<asp:Label ID="IngredientNineLabel" runat="server"
Text='<%# Eval("IngredientNine") %>' /><br />
<asp:Label ID="IngredientTenLabel" runat="server"
Text='<%# Eval("IngredientTen") %>' /><br />
</td>
</tr>
<tr>
<td>
<asp:Label ID="DirectionOneLabel" runat="server"
Text='<%# Eval("DirectionOne") %>' />
</td>
<td>
<asp:Label ID="DirectionTwoLabel" runat="server"
Text='<%# Eval("DirectionTwo") %>' />
</td>
<td>
<asp:Label ID="DirectionThreeLabel" runat="server"
Text='<%# Eval("DirectionThree") %>' />
</td>
<td>
<asp:Label ID="DirectionFourLabel" runat="server"
Text='<%# Eval("DirectionFour") %>' />
</td>
</tr>
</itemtemplate>
<layouttemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
</tr>
<tr runat="server" ID="itemPlaceholder">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</layouttemplate>
</asp:ListView>
This is the .cs for Details.aspx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DetailPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource used with ListView
Nov 12, 2012 11:52 PM|LINK
Hello,
Since you've passed this to the DetailsPage.aspx——So I don't see you've done anything to do with category's Id?
In fact I think you should use QueryStringParameter:
<asp:SqlDataSource ID="AfricanRecipesDirectionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [AfricanRecipesDirections] where categoryId=@categoryid"> <SelectParameters> <asp:QueryStringParameter Name="categoryid" QueryStringField="category" Type="Int32"/> </SelectParameters> </asp:SqlDataSource>EarlDavis1
0 Points
8 Posts
Re: SqlDataSource used with ListView
Nov 13, 2012 05:43 PM|LINK
Decker,
I made the correction you suggested with the following results:
1. The AfricanRecipes.aspx now gives an error message: "Input string was not in a correct format."
2. The Details.aspx will open, however, it shows no data, not even a "No data returned" message.
The reason the Detail.cs had no category=" entry is because I had tried everythin, and nothing seemed to work.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource used with ListView
Nov 14, 2012 12:10 AM|LINK
What's the value of your categoryId? It must be a numeric value.
EarlDavis1
0 Points
8 Posts
Re: SqlDataSource used with ListView
Nov 15, 2012 02:33 PM|LINK
Decker, I appreciate your help. I am a newbie, and have spent well over 100 hours trying to find the solution to my problem. I think perhaps your last question is close to the solution but I am not sure. After making the above changes that you suggested, the AfricanRecipes.aspx page did render the ListView, but when the link was click, the error message "....incorrect format" came up. From what you said, it would appear that the AfricanRecipe.aspx page does not know, via the "category" in the connection string, where to go on the Detail.aspx page.
On both the AfricanRecipes.aspx ListView and the Details.aspx ListView, "Category" is the primary key in both dbs, with a database type "int" and both are 'non-nullable". The first row, first column, is "Category" on both dbs and is "1".
1. Can you give me the link format, which I assume would go in the AfricanRecipes.aspx.cs, which would take me to the first row of the db in the Details.aspx, and then to the subsequent rows as I click each decending link on the AfricanRecipes.aspx page? The following is the code on the AfricanRecipes.aspx.cs:
public partial class AfricanRecipes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetUrl(object id, object category)
{
string url = "~/DetailPage.aspx?category=" + id.ToString() + "&category=" +
Server.UrlEncode(category.ToString());
return url;
}
}
You gave me the following to put into the Details.aspx page. Would the "categoryID" on this page have to be changed to the same as on the AfricanRecipes.aspx.cs?
<asp:SqlDataSource ID="AfricanRecipesDirectionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [AfricanRecipesDirections] where categoryId=@categoryid"> <SelectParameters> <asp:QueryStringParameter Name="categoryid" QueryStringField="category" Type="Int32"/> </SelectParameters> </asp:SqlDataSource> Again, thank you very much for your help.Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource used with ListView
Nov 16, 2012 12:26 AM|LINK
Please make sure that id can be convertable to numeric.
And
You've defended duplicated "categroy", so you should remove one of them and change to this:
public string GetUrl(object id, object category) { string url = "~/DetailPage.aspx?category=" + id.ToString(); return url; }