对HTML超链接来查询数据库中创建函数 [英] create functions for html hyperlinks to query database

查看:107
本文介绍了对HTML超链接来查询数据库中创建函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后端称为简单的网上购物在 asp.net C#和MySQL数据库创建Web应用程序,

i have created a web application in asp.net with C# and MySql Database at the backend called simple online shopping,

我已创建了无序列表和HTML超链接 A 级联下拉横向导航菜单(navmenu)。我有2页 Homepage.aspx和ShowProducts.aspx

I have created a cascading dropdown horizontal navigation menu (navmenu) with unordered lists and html hyperlinks. i have 2 pages Homepage.aspx and ShowProducts.aspx.

Navmenu包含在一个层次结构中的类别和产品类的数据存储在数据库中。
当点击了navmenu连结我想的,以显示包含在ShowProducts.aspx类别中的产品
我在无序列表列表项中的层次navmenu

Navmenu contains the categories in an hierarchy and the products and category data is stored in databases. when a hyperlink is clicked on the navmenu i wanted the to show the products contained in the category in the ShowProducts.aspx i have list item in unordered lists in navmenu in hierarchy of

1.Clothing结果
 1.1:男装结果
    1.1.1:衬衫结果
    1.1.2:长裤结果
    1.1.3:WinterWear

1.Clothing
1.1:Mens
1.1.1:Shirts
1.1.2:Trousers
1.1.3:WinterWear

1.2:女装结果
    1.2.1:休闲服结果
    1.2.2:牛仔裤结果
    1.2.3手袋

1.2:Womens
1.2.1:Casual Wear
1.2.2:Jeans
1.2.3 Bags

我已经写了超链接为:

    <ul id="navmenu">
<li><a href="ShowProducts.aspx">Clothing</a>
<ul class="sub1">
                    <li><a href="ShowProducts.aspx">Mens</a>
                        <ul class="sub2">
   <li><a href="ShowProducts.aspx">Shirts</a></li>
                            <li><a href="ShowProducts.aspx">Mens Trousers</a></li>
                            <li><a href="ShowProducts.aspx">Jeans</a></li>
                            <li><a href="ShowProducts.aspx">Winter wear</a></li>
                            <li><a href="ShowProducts.aspx">Watches & Bags</a></li>
                            <li><a href="ShowProducts.aspx">Footwear for men</a></li>
  </ul>
                    </li>
                    <li><a href="ShowProducts.aspx">Womens</a>
                        <ul class="sub2">
                            <li><a href="ShowProducts.aspx">Sarees & Dresses</a></li>
                            <li><a href="ShowProducts.aspx">Jewellery</a></li>
                            <li><a href="ShowProducts.aspx">Womens Jeans</a></li>
                            <li><a href="ShowProducts.aspx">Womens Bags</a></li>
                            <li><a href="ShowProducts.aspx">Footwear for Women</a></li>
   </ul>
                    </li>
                </ul>
            </li>

我使用Devart的 linqconnect(LINQ到MySQL)。有人告诉我,使用查询字符串以通过页面之间的数据,但它包含的图像和数据,所以我想使用转发,以显示他们在hiererchy 。可以点击数处理程序中添加一个&LT; A&GT; 标记,以便谱写的 JavaScript函数

I am using Devart linqconnect(Linq To MySql). some one told me to use querystrings to pass data between pages but it contains images and data so i wanted to use repeaters to show them in hiererchy. Could add an onlick handler to<a> tag so and write a javascript function such as

    <script type="text/javascript">

功能展示Products(){

Function showproducts() {

     -- Linq code to retrieve products based on id --   

}

可能有人提出一个很好的方法,或者告诉我怎样才能做到这一点。
感谢..请帮助我在此。

could anybody suggest a good method or tell how can i achieve this. thanks.. please help me on this..

推荐答案

使用中继器来渲染你的页面上的链接列表。 1添加查询字符串值类似ShowProduct.aspx?ID =到每一个环节。

Use Repeater to render list of links on your page. Add query string value like ShowProduct.aspx?id=1 to every link.

在显示产品页面,使用LINQ从数据库检索数据:

On ShowProduct Page, use linq to retrieve data from DB:

using(DataContext db = new DataContext())
{
    int id = Convert.ToInt32(Request.QueryString["id"]);
    var product = db.products.Where(p => p.id = id).FirstOrDefault();
    if(product != null)
    {
        //do your job here with product data
    }
}

这篇关于对HTML超链接来查询数据库中创建函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆