English 中文(简体)
如何从 ASP.Net 网格查看列字段链接到.aspx 页面
原标题:How to link from an ASP.Net gridview column field to an .aspx page

我使用 asp.net 网格视图来显示 mdb 文件的数据列表。 有 5 列显示, 约 240 行数据。 每行显示“ 名 ” 、 姓 、 “ 标题 ” 、 “ 流 ” 、 “ 问题 ” 和“ id ” 。

Each "title" entry has corresponding .aspx page. There are approximately 180 actual .aspx pages that corresponds to the "title" entries in the grid. An example of this relationship looks like: title = "Once upon a time in a long story"; and the aspx page might be /alongstory.aspx.

我想完成的是:允许用户单击网格上的标题字段,打开相应的.aspx 页面。

我至今所做的是:在“标题”字段上创建了一个 aspLabel - Text= <\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\C#C# 代号标签负载事件。

    aspLabel l = sender as aspLabel;
    l.ClientsideEvents.Click = String.Format("function(s,e) {{window.location = "{0}"; }}, GetPageUrl(l));

和GetPageUrl:

     Private string GetPageUrl(aspLabel l)
     {GridViewDataItemTemplateContainer c = l.NamingContainer as GridViewDataItemTemplateContainer:
    var value = (string)DataBinder.Eval(c.DataItem, "Title"); 
    string result;
    switch (value) {
         case "in the mirror":
            result = "AnotherTitlePage.aspx";
            break;
        case "When your Eyes":
            result = "AnotherTitlePage2.aspx";
            break;
        case "Her Delivery":
            result = "ATitlePage1.aspx";
            break;
        case "You Never Know What You Might See":
            result = "TitlePage3.aspx";
            break;              
        default:
            result = "TitlePageDoesNotHavesameNameAsDBEntry.aspx";
            break;
    }
    return Page.ResolveUrl(result);
}

在此工作的同时, 它要求所有标题都硬化编码为相应的选择语句, 并加上与 comroponding url 等同于 240 个案例的 URl 。 此外, 唯一唯一唯一能识别每行的字段是“ id” 值, 在整数中 - 我尝试设置一个用于 int 的选项并返回正确的 url 时遇到了问题( 选择错误是问题 ) 。

What I hope to accomplish: Find the most efficient way to open the corrosponding url for the click on the "title" field of the grid view without hard coding both the field name from the grid column and the url into the case select.

So, given the information above, would a case select be the best approach for this requirement? Any examples or suggestions of better approaches would be most appreciated!

问题回答

您必须使用在 c# 4. 0 和 c4. 0 以上 中引入的路线概念, 而不是制作 180 个实际的.aspx 页面 。

您可以在此动态生成 N 页数, 只有一页可以作为模板工作 。

详情请见下链接。

"http://www.codeproject.com/articles/77199/URL-Routing- with-ASP-NET-4-0" rel=“nofollow”>URL Routing in asp.net 例如www.jobdoor.in





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签