【发布时间】:2017-04-08 05:44:58
【问题描述】:
我有如下所示的 sql 表 dbo.Clicks:
ColNum Color RowNum Message
1 Gold 1 Text1
1 Black 2 Text2
2 Red 2 MoreText
2 Blue 3 TextX
我的存储过程像这样返回相同的数据。这是底层datatable:
Col1 Col2
-----------------------
Gold (null)
Black Red
(null) Blue
我在RowDataBound中填写每个单元格:
protected void GridViewClicks_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
cell.BackColor = ConvertFromHexToColor(cell.Text);
}
}
}
此代码有效,因为它用相应的背景色填充单元格。
现在的问题是我还需要在每个单元格中显示我的 sql 表 [dbo.Clicks] 的内容。这就是我卡住的地方。
如果我使用示例数据,另一种方法是每个数据表单元格都包含颜色和文本,类似这样。然后我解析它:
Col1 Col2
Gold/Text1 (null)
Black/Text2 Red/MoreText
(null) Blue/TextX
但我认为必须有一种更优雅的方式来做到这一点。对我来说,这个解决方案非常难看。
我的网格视图如下所示:
<asp:GridView ID="GridViewClicks" runat="server" ShowHeader="False" onrowdatabound="GridViewClicks_RowDataBound">
</asp:GridView>
谢谢。
【问题讨论】:
标签: c# asp.net visual-studio-2010 gridview