如何获得GridView的LinkBut​​ton的前景色在RowCommand事件? [英] How to get GridView's LinkButton ForeColor in RowCommand Event?

查看:195
本文介绍了如何获得GridView的LinkBut​​ton的前景色在RowCommand事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView有以下的列。

I have a GridView with the following columns.

 <Columns>
     <asp:TemplateField HeaderText="Item Description">
     <ItemTemplate>
     <asp:Label ID="lblgvItemName" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label>
     </ItemTemplate>
     </asp:TemplateField>
    <asp:BoundField DataField="IssueQty" HeaderText="Issue Qty" />
    <asp:TemplateField>
    <ItemTemplate>
       <asp:LinkButton ID="lnkReturn" runat="server" CommandName="Return" CommandArgument='<%# Eval("ItemName") + "," + Eval("IssueQty") + %>' Text="Return" Font-Bold="true" ForeColor="Red">
       </asp:LinkButton>
    </ItemTemplate>
 </Columns>

在我需要的得到的LinkBut​​ton的前景色在GridView的RowCommand事件。基于前景色,我做了一些验证。

In that I need the get the ForeColor of the LinkButton in the RowCommand event of the GridView. Based on the ForeColor, I am doing some validation.

我试过这样的,

 string Color = ((LinkButton)gvRIVDetails.Rows[Convert.ToInt32(e.CommandArgument.ToString()].FindControl("lnkReturn")).ForeColor;

但我在命令参数已经指定ITEMNAME和IssueQty。所以它会抛出异常。
如何找到的LinkBut​​ton的前景色?

But I have already specified ItemName and IssueQty in the Command Argument. So it throws the exception. How to find the ForeColor of the LinkButton?

推荐答案

这会帮助你。请大家看看。

This will help you. Please take look.

            GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;

        LinkButton lstText = (LinkButton)row.FindControl("lnkReturn");

        string text = lstText.ForeColor.ToString();

这篇关于如何获得GridView的LinkBut​​ton的前景色在RowCommand事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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