如何在ASP.Net中创建动态链接 [英] How to create dyanamic links in ASP.Net

查看:84
本文介绍了如何在ASP.Net中创建动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我的方案就像我在数据库中有两张桌子

1.零售商列表

2. StoreList



在第一张表中,我列出了想参加我们活动的零售商名单

在第二张表中,我有这些零售商所拥有的商店。 br />
一个零售商可能有任意数量的商店。



我有一个Aspx页面我正在从第一个表格动态加载零售商列表我想当用户点击该零售商时,它应该重定向到另一个aspx页面,该页面将显示零售商拥有的所有商店,其中包含来自表2的常见信息。

我只能填充零售商列表,但后来的情况是看起来单调乏味。



谢谢

解决方案

Quote:

我只能填充零售商列表,但后来的情况看起来很乏味。

为什么呢?这很简单。看我的逻辑。





建议逻辑

假设



StoreList 包含 RetailerId 作为参考或外键

如果没有,那么你需要相应地修改逻辑。

逻辑



  • 点击特定的零售商,只需将 ID 作为 QueryString 到下一页(商店页面),比如...

      var  retailerId =   yourRetailerId; 
    Response.Redirect( Stores.aspx?RetailerID = + HttpUtility.UrlEncode(retailerId ));

  • 现在,在商店页面上,检索 QueryString 的值 RetailerID
  • 查询数据库 StoreList 对于那个特定的零售商喜欢...

      SELECT  Col1,Col2,Col3  FROM  StoreList 
    WHERE
    RetailerId = yourQueryStringRetailerId





注意

用实际替换 Col1,Col2,Col3 列名。

ADO.NET 对象的帮助下执行此查询并传递 QueryString 正确指向查询


Hi
My scenario is like I have two tables in database
1. RetailerList
2. StoreList

In first table I have a list of retailers who want to participate in our events
In second table I have stores that those retailers have.
One retailer may have any number of stores.

I have a Aspx page on which I am loading List of retailers dynamically from first table and I want when user click on that retailer, it should redirect to another aspx page which will show all store that retailer have with common info from table 2.
I can only populating Retailers list, but later scenario is looking tedious.

Thanks

解决方案

Quote:

I can only populating Retailers list, but later scenario is looking tedious.

Why? It's easy. See my Logic.


Proposed Logic

Assumption


StoreList contains RetailerId as a Reference or Foreign Key.
If not, then you need to modify the logic accordingly.

Logic


  • On Click of a particular Retailer, just pass his ID as a QueryString to the Next Page (Stores Page) like...

    var retailerId = "yourRetailerId";
    Response.Redirect("Stores.aspx?RetailerID=" + HttpUtility.UrlEncode(retailerId));

  • Now, on the Stores Page, retrieve the QueryString value for RetailerID.
  • Query to Database Table StoreList for that particular Retailer like...

    SELECT Col1, Col2, Col3 FROM StoreList
    WHERE
    RetailerId = "yourQueryStringRetailerId"



Note
Replace Col1, Col2, Col3 with actual Column Names.
Execute this Query with the help of ADO.NET objects and pass the QueryString value correctly to the Query.


这篇关于如何在ASP.Net中创建动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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