0

GridView启用了选择。我想以编程方式更改这些链接的样式,但我不确定如何访问它们。我已经使用选择器将 CSS 应用于它们a,但我无法通过代码执行此操作。

如何使用 C# 修改这些按钮的外观?

4

2 回答 2

0

Try Below Code:

<asp:GridView ID="gvUserInfo" runat="server" 
    onrowdatabound="gvUserInfo_RowDataBound1">
 <Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkButton" runat="server" Text="Link"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



protected void gvUserInfo_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnk = e.Row.FindControl("lnkButton") as LinkButton;
            lnk.ForeColor = System.Drawing.Color.Red;
        }
    }
于 2013-07-26T12:01:16.733 回答
0

因为我的网格视图是一个表格,你可以使用 CSS

<html>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RegNo" DataSourceID="SqlDataSource1" Width="931px" CellPadding="4" ForeColor="#333333" GridLines="None" Height="170px" AutoGenerateDeleteButton="True">
</asp:GridView>
<style>
    td > a {
        /*button*/
        display: inline-block;
        margin-bottom: 0;
        font-weight: normal;
        text-align: center;
        vertical-align: middle;
        -ms-touch-action: manipulation;
        touch-action: manipulation;
        cursor: pointer;
        background-image: none;
        border: 1px solid transparent;
        white-space: nowrap;
        padding: 4px 8px;
        font-size: 14px;
        line-height: 1.42857143;
        border-radius: 4px;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /*button color*/
        color: #ffffff;
        background-color: #c71c22;
        border-color: #c71c22;
    }

        td > a:hover {
            color: #555555;
            text-decoration: none;
            background-color: #9a161a;
            border-color: #911419;
        }

于 2018-05-20T13:37:26.270 回答