gridview中的按钮将用户重定向到url

时间:2011-01-11 16:24:38

标签: c# .net asp.net gridview .net-4.0

我正在研究一种允许某些员工查看客户调查结果的经理。我正在跟踪进行调查的客户的IP地址,并向可以查看结果的员工显示该IP地址。我正在使用带有sqldatasource的gridview来从数据库中提取数据并显示它。 我想要做的是添加一个带有IP地址的按钮或链接,并将其附加到网站的网址,以跟踪地图上的IP地址的位置。我已经注册了一个服务器,但我不确定如何编码。

这是我的Gridview

<asp:GridView ID="GVnewsletterManager" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" 
    BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
    CellPadding="4" DataKeyNames="email_time" ForeColor="Black" 
    GridLines="Horizontal" Width="100%" PageSize="15">
    <Columns>
        <asp:BoundField DataField="email_time" HeaderText="Length of Email Subscription" 
            SortExpression="email_time" />
        <asp:BoundField DataField="reason" HeaderText="Reason for Unsubscribe" 
            SortExpression="reason" />
            <asp:BoundField DataField="other" HeaderText="Other Reason" 
            SortExpression="other" />
        <asp:BoundField DataField="other_comments" HeaderText="Other Comments" SortExpression="other_comments" 
            ReadOnly="True" />
        <asp:BoundField DataField="DateTime" HeaderText="Date" 
            SortExpression="DateTime" />
        <asp:BoundField DataField="IP" HeaderText="Client IP" SortExpression="IP" />
        <asp:ButtonField ButtonType="Button" Text="Trace IP to Map" />
    </Columns>
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" 
        HorizontalAlign="Left" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

尝试使用HyperLinkField

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx

<asp:HyperLinkField
                 HeaderText="Client IP"
                 DataNavigateUrlFields="IP"
                 DataNavigateUrlFormatString="some-page.aspx?id={0}"
                 DataTextField="IP"
                 DataTextFormatString="{0}"
                 Target="_blank"/>