本文介绍了如何将样式仅应用于datagrid中的一个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在DataGrid中显示数据.
在该DataGrid中有5列.它们是EmpID,Ename,Esal,EDept,Location.
我只想更改Ename单元格.
我想给背景和边框加上颜色并应用边框样式.
我该怎么办?
请给我一个解决方案.
谢谢
Hi,
I am displaying data in DataGrid.
In that DataGrid there are 5 columns. They are EmpID, Ename, Esal, EDept, Location.
I want to change only Ename cell.
I want to give a color to background and border and apply border style.
How do I do it?
Please gime me a solution.
Thanks
推荐答案
<asp:GridView ID="grid" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate style="background-color: Green">
</ItemTemplate>
</asp:TemplateField>
</Columns>
...
...
...
</asp:GridView>
如果有帮助,请 投票 和 接受答案 .
Please vote and Accept Answer if it Helped.
protected void GridName_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// get a reference to the data used to databound the row
DataRowView row = (DataRowView)e.Row.DataItem;
// Check the row, do something based on the condition of a row value?
// if (row[7].ToString() == "Test")
// {
// e.Row.Style.Add("Something", "class-name");
// }
}
}
这篇关于如何将样式仅应用于datagrid中的一个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!