我使用 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!