我有一个gridview,它以下面的形式显示记录:
Date Total Enrolled Enrolled as Email Enrolled as Text
2/29/2012 12:00:00 AM 1 0 1
2/28/2012 12:00:00 AM 2 1 1
2/27/2012 12:00:00 AM 23 11 12
2/25/2012 12:00:00 AM 1 1 0
2/24/2012 12:00:00 AM 16 9 7
使用此查询显示记录:
select created,
count(field1) Enrolled,
count(case field1 when 'E-mail' then 1 end) Enrolled_as_Email,
count(case field1 when 'Cell Phone' then 1 end) Enrolled_as_Cell,
(Select COUNT(*)
from tbl_TransactionDishout d
where d.created = c.created and
d.DishoutResponseCode = '0000') Deals_Redeemed
from tblCustomer c
group by created
order by created
ASP.NET代码如下:
<asp:GridView ID="GrdReport" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="1" DataKeyNames="Created" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" PageSize="100"
onrowdatabound="GrdReport_RowDataBound">
<Columns>
<asp:BoundField DataField="Created" HeaderText="Date" SortExpression="Created" />
<asp:BoundField DataField="Total_Enrolled" HeaderText="Total Enrolled" SortExpression="Total_Enrolled" />
<asp:BoundField DataField="Enrolled_as_Email" HeaderText="Enrolled as Email" SortExpression="Enrolled_as_Email" />
<asp:BoundField DataField="Enrolled_as_Cell" HeaderText="Enrolled as Text" SortExpression="Enrolled_as_Cell" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" Height="4" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Right" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ appSettings:DBConn %>"
SelectCommand="select created, count(field1) Total_Enrolled, count(case field1 when 'E-mail' then 1 end) Enrolled_as_Email, count(case field1 when 'Cell Phone' then 1 end) Enrolled_as_Cell from tblCustomer group by created order by created desc">
</asp:SqlDataSource>
现在我希望这个号码是一个超链接,它将页面重定向到显示那些记录的其他页面。
那应该怎么做呢。我应该在查询字符串中传递什么,以便我可以在重定向的页面上识别它...以及如何?
答案 0 :(得分:2)
你的linke看起来像这样......
http://address/page.aspx?parameter=value&nextparameter=value
http://localhost/newpage.aspx?email=0&text=1
在您的asp.net页面中,您可以像这样访问查询字符串Request.QueryString["email"];
Request.QueryString["text"];
这只是一种简单的方法......如果你构建复杂的webapps,你应该采取更多,但这可以让你开始
如果我理解你的问题是正确的......
您应该确保对值进行编码以使其安全...
编辑:构建链接使用超链接字段
<asp:hyperlinkfield datatextfield="UnitPrice"
datatextformatstring="{0:c}"
datanavigateurlfields="ProductID"
datanavigateurlformatstring="~\details.aspx?ProductID={0}"
headertext="Price"
target="_blank" />
使用多个参数逗号将它们分开,就像这样
<asp:HyperLinkField DataTextField="CategoryName"
DataNavigateUrlFields="CategoryID,CategoryName,Description"
DataNavigateUrlFormatString="~/Learning.aspx?categoryID={0}&categoryName={1}&description={2}"
/>
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx
然后你需要第二个页面来解析细节并根据传递的值查询结果......