如何在gridview c#asp.net中添加超链接到boundfield [英] How to add hyperlink to boundfield in gridview c# asp.net

查看:290
本文介绍了如何在gridview c#asp.net中添加超链接到boundfield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面中有一个gridview,一旦用户单击Component1值,我需要它从BoundField添加超链接到组件。

I have a gridview in aspx page, I need it to go add hyperlink to the Component from BoundField once the user clicks on the Component1 value. How can I add the hyperlink to boundfield that's related to BoundField?

<asp:GridView ID="Module" runat="server" AutoGenerateColumns="False" BackColor="White"
        BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
        DataSourceID="dsrcGetModuleData" Font-Size="0.65em" ForeColor="Black" GridLines="Vertical" DataKeyNames="TestID">
        <FooterStyle BackColor="#CCCC99" />
        <Columns>

<asp:BoundField DataField="Component1"  ItemStyle-Font-Size="Small" HeaderStyle-Width="80px"  HeaderStyle-Font-Size ="Medium" SortExpression="Component1"   /> 

</Columns>
        <RowStyle BackColor="#F7F7DE" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right"  />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White"  />
    </asp:GridView>


推荐答案

试试这个。

Try this.

 <asp:GridView ID="Module" runat="server" AutoGenerateColumns="False" BackColor="White"
    BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
    DataSourceID="dsrcGetModuleData" Font-Size="0.65em" ForeColor="Black" GridLines="Vertical" DataKeyNames="TestID">
    <FooterStyle BackColor="#CCCC99" />
 <Columns>
  <asp:HyperLinkField DataNavigateUrlFields="StockNumber" HeaderText="Stock Number" DataNavigateUrlFormatString="ReplacePage.aspx?StockNumber={0}" DataTextField="StockNumber" />
 </Columns>
 <RowStyle BackColor="#F7F7DE" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right"  />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White"  />
 </asp:GridView>

要传递多个变量,请执行此操作。

To pass more than one variable, do this.

 <asp:GridView ID="Module" runat="server" AutoGenerateColumns="False" BackColor="White"
    BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
    DataSourceID="dsrcGetModuleData" Font-Size="0.65em" ForeColor="Black" GridLines="Vertical" DataKeyNames="TestID">
    <FooterStyle BackColor="#CCCC99" />
 <Columns>
  <asp:HyperLinkField DataNavigateUrlFields="StockNumber, ID, CITY" HeaderText="Stock Number" DataNavigateUrlFormatString="ReplacePage.aspx?StockNumber={0}&id={1}&CITY{2}" DataTextField="StockNumber" />
 </Columns>
 <RowStyle BackColor="#F7F7DE" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right"  />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White"  />
 </asp:GridView>

DataNavigateUrlFields - 您希望通过超链接列传递的字段。

DataNavigateUrlFields - The fields you would like to pass using the hyperlink column.

DataTextField - DatagridView中的当前显示字段。

DataTextField - Current display field in the DatagridView.

HeaderText - 标题文本,应该是DataTextField值的描述。

HeaderText - header text which should be the description of the DataTextField value.

这篇关于如何在gridview c#asp.net中添加超链接到boundfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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