I am working on a class project and it was all going exceptionally well until I came to the part where I would like to pass the information from whatever item is clicked on in a ListView to another page (like when online shopping you get a details page).
I have gotten the database to display in the ListView, I have the ListView looking how I want it, but I just haven't been able to find any info on how to send which row of the database to the next page.
Is this even possible with an Access Database? and if so could someone please point me in the right direction.
I'm not using Routing and we haven't even been taught it. Tbh it might be out of my current scope. What I can get working is a dropdown list to send info to a cart but I'd like to use something other than a dropdown list, since thats exactly what the textbook
uses.
I came to the part where I would like to pass the information from whatever item is clicked on in a ListView to another page
In fact,Just put a hyperlink bound with the primary key of the cetain Product, and when you click that, it will automatically guide you where you wanto go:
Sample:
<a href='<%#Eval("Id","Details.aspx?id={0}"%>'> Click Here To See Details……<a/>
chogreshi
0 Points
2 Posts
Access database with ListView, Want to send item clicked to another page.
Apr 14, 2012 01:03 AM|LINK
I am working on a class project and it was all going exceptionally well until I came to the part where I would like to pass the information from whatever item is clicked on in a ListView to another page (like when online shopping you get a details page). I have gotten the database to display in the ListView, I have the ListView looking how I want it, but I just haven't been able to find any info on how to send which row of the database to the next page.
Is this even possible with an Access Database? and if so could someone please point me in the right direction.
Thank you.
rickj1
Member
385 Points
203 Posts
Re: Access database with ListView, Want to send item clicked to another page.
Apr 14, 2012 02:03 AM|LINK
Are you using Routing if so make a link like this this Route you use the department ID to select all of the categories in this departement
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='<%#"/department/"+ Eval("DepartmentNameUrl")+"/"+Eval("DepartmentID") %>'><%# Eval("Name") %></asp:HyperLink>here is the Route with regex validation
void RegisterRoutes (System.Web.Routing.RouteCollection routes) { routes.MapPageRoute("Departments", "department/{name}/{Id}", "~/Department.aspx",true , new RouteValueDictionary { { "Id", "[0-9]{1,8}" } }); {Remember to Register your routes in the application start in the global.ascx file
void Application_Start(object sender, EventArgs e) { RegisterRoutes(System.Web.Routing.RouteTable.Routes); }These tutorials are a good place to start
http://www.asp.net/web-forms/overview/routing
www.barterlinks.net
chogreshi
0 Points
2 Posts
Re: Access database with ListView, Want to send item clicked to another page.
Apr 14, 2012 04:02 AM|LINK
I'm not using Routing and we haven't even been taught it. Tbh it might be out of my current scope. What I can get working is a dropdown list to send info to a cart but I'd like to use something other than a dropdown list, since thats exactly what the textbook uses.
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox> <asp:Button ID="btnAdd" runat="server" Text="View" CssClass="button" onclick="btnAdd_Click1" /> </div> <asp:DropDownList ID="ddlProducts" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource1" DataTextField="Name" DataValueField="ProductID"> </asp:DropDownList> <asp:ListView ID="ProductListView" runat="server" DataSourceID="AccessDataSource1" DataKeyNames="ProductID"> <LayoutTemplate> <div ID="itemPlaceholderContainer" runat="server" style=""> <span runat="server" id="itemPlaceholder" /> <asp:PlaceHolder ID="itemContainer" runat="server" /> </ul> <asp:DataPager ID="DataPager1" runat="server" PageSize="4"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /> </Fields> </asp:DataPager> </div> </LayoutTemplate> <ItemTemplate> <div class="product"> <a href="Default.aspx"><img src="Images/Products/<%#Eval("ImageFile") %>" title="<%#Eval("ShortDescription") %>"/></a><br /> <a href ="Default.aspx"><h2><%#Eval("Name") %></h2></a> <h4><asp:Label runat="server" ID="lblId2"><%#Eval("ShortDescription") %></asp:Label></h4><br /> <h3> SKU: <%#Eval("Sku") %></h3> <asp:Label runat="server" ID="lblId3"><%#Eval("Price") %></asp:Label><br /><br /> <asp:Button ID="View_Btn" runat="server" Text="View" CssClass="button" /> <a href='Detail.aspx?productID=<%# Eval("ProductID") %>'> <span class="ProductListItem"><b>Add To Cart<b></font></span> </a> </div> </ItemTemplate> <EmptyDataTemplate> <div> Sorry - No products here </div> </EmptyDataTemplate> </asp:ListView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/propaneDB.mdb" SelectCommand="SELECT [ProductID], [Name], [ShortDescription], [LongDescription], [Price], [ImageFile], [Sku] FROM [propaneBarbeque]"> </asp:AccessDataSource>That is the code that is in my aspx file.
public partial class Default2 : System.Web.UI.Page { private Product selectedProduct; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) ddlProducts.DataBind(); selectedProduct = this.GetSelectedProduct(); } private Product GetSelectedProduct() { DataView productsTable = (DataView) AccessDataSource1.Select(DataSourceSelectArguments.Empty); productsTable.RowFilter = "ProductID = '" + ddlProducts.SelectedValue + "'"; DataRowView row = (DataRowView)productsTable[0]; Product p = new Product(); p.ProductID = row["ProductID"].ToString(); p.Name = row["Name"].ToString(); p.ShortDescription = row["ShortDescription"].ToString(); p.LongDescription = row["LongDescription"].ToString(); p.UnitPrice = (decimal)row["Price"]; p.ImageFile = row["ImageFile"].ToString(); return p; } protected void btnAdd_Click1(object sender, EventArgs e) { if (Page.IsValid) { CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.ProductID]; if (cartItem == null) { cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text)); } else { cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text)); } Response.Redirect("Cart.aspx"); } } }and That is my code behind. With a few classes being used to send to cart.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Access database with ListView, Want to send item clicked to another page.
Apr 16, 2012 01:58 AM|LINK
In fact,Just put a hyperlink bound with the primary key of the cetain Product, and when you click that, it will automatically guide you where you wanto go:
Sample:
<a href='<%#Eval("Id","Details.aspx?id={0}"%>'> Click Here To See Details……<a/>