开发者

ASP.NET Gridview: How to access the Select button?

I am getting there! Need a tiny bit of extra help. My gridview has 2 columns. One is Party (text) and one is a Select column with a Select button in every row. This is what I want: Change the color of the Select button to Red if 开发者_StackOverflowthe Party is Republican. Otherwise set it to Blue. Below is the code I have. Please help me fill in the missing code.

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text == "Republican")
                 {
                  // WHAT SHOULD I DO HERE???
                 }
        }


    }


Instead of setting the color in the codebehind you could just set the CSS Class of your button in the aspx file, using gridview's template fields:

<templateField>
    <itemtemplate>
        <asp:button runat="server" id="selectButton" CSSClass='<%# Eval("PARTY") %>' />
    </itemTemplate>
</templateField>

and then defining the CSS Class in your stylesheet.

.republican{background-color:#F00;}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜