Getting value from a cell from a gridview on RowDataBound event

前端 未结 12 1027
[愿得一人]
[愿得一人] 2020-12-23 16:48
string percentage = e.Row.Cells[7].Text;

I am trying to do some dynamic stuff with my GridView, so I have wired up some code to the RowDataBound ev

12条回答
  •  眼角桃花
    2020-12-23 17:44

    The above are good suggestions, but you can get at the text value of a cell in a grid view without wrapping it in a literal or label control. You just have to know what event to wire up. In this case, use the DataBound event instead, like so:

    protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text.Contains("sometext"))
            {
                e.Row.Cells[0].Font.Bold = true;
            }
        }
    }
    

    When running a debugger, you will see the text appear in this method.

提交回复
热议问题