How do I specify CSS classes for specific rows in a GridView?

后端 未结 2 1296
清酒与你
清酒与你 2021-01-11 11:25

I am creating a SharePoint web part in C# and part of it outputs a GridView control to the page. While I can get fairly extensive control over the way it is displayed by set

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-11 12:15

    Optional! you can also add bootstrap class in code behind like...

    protected void gvEmpContactsHistory_SelectedIndexChanged(object sender, EventArgs e)
        {
            string val = Convert.ToDateTime(gvEmpContactsHistory.SelectedDataKey.Value).ToString("dd-MM-yyyy hh:mm:ss", new System.Globalization.CultureInfo("en-US"));
            GetEmployeeDetail(val);
    
            foreach (GridViewRow row in gvEmpContactsHistory.Rows)
            {
                if (row.RowIndex == gvEmpContactsHistory.SelectedIndex)
                {
                    row.ToolTip = string.Empty;
                    row.Attributes.Add("class", "btn-success");
                }
                else
                {
                    row.ToolTip = "Click to select this row.";
                    row.Attributes.Add("class", "btn-outline-success");
                }
            }
        }
    

提交回复
热议问题