简体   繁体   English

访问GridView ItemTemplate控件ASP.NET

[英]Access GridView ItemTemplate control ASP.NET

I am using ASP.NET GridView on ASPX page: 我在ASPX页面上使用ASP.NET GridView:

<asp:GridView ID="GrdLimitAndUtilization" runat="server" AutoGenerateColumns="False" GridLines="None"
                    Width="99%" meta:resourcekey="GrdAccountListResource1" OnRowDataBound="GrdLimitAndUtilization_RowDataBound"
                    ShowHeader="True" rowstyle-cssclass="rowHover" ClientIDMode="Static" CssClass="gridView">
                    <Columns>
<asp:TemplateField HeaderText="Excess" meta:resourcekey="Excess">
                            <HeaderStyle HorizontalAlign="Left" Width="120px" CssClass="gridheader" />
                            <HeaderTemplate> <asp:Label ID="col5a" Text="Excess" runat="server"></asp:Label></HeaderTemplate>
                            <ItemTemplate>
                                <asp:HyperLink ID="lnkExcess" runat="server" value='' Text='<%# Bind("Excess") %>'
                                    meta:resourcekey="HyperLink1Resource1"></asp:HyperLink>
                                <asp:Label ID="Excess_Currency" runat="server" Text='<%# Bind("Currency") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="120px" HorizontalAlign="Left" CssClass="customerProductItemTemp gridviewLeftMargin" />
                        </asp:TemplateField>
                    </Columns>
</asp:GridView>

I know I can access GridView column by following code: 我知道我可以通过以下代码访问GridView列:

GrdLimitAndUtilization.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Green;

BUT, How can I access value/text of only HyperLink control with ID="lnkExcess"?? 但是,如何才能访问ID =“lnkExcess”的HyperLink控件的值/文本?

Thanks. 谢谢。

You can use RowDataBound event like this:- 您可以像这样使用RowDataBound事件: -

protected void GrdLimitAndUtilization_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink lnkExcess = (HyperLink)e.Row.FindControl("lnkExcess");
        //Access hyperlink's properties here.
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM