我有一个显示两个表格的gridview(使用合并方法)。我想要改变第0行和第11行的颜色。我知道可以在行数据绑定事件中实现,但是我不知道如何在运行时选择这些行。
我的后台代码:
public void mergetbl(DataTable DocVisTbl, DataTable cobtable)
{
DataTable mergetable = DocVisTbl.Copy();
mergetable.Merge(cobtable);
DataRow row;
row = mergetable.NewRow();
row["Stakeholder"] = "Número de Médicos";
mergetable.Rows.InsertAt(row, 0);
row = mergetable.NewRow();
row["Stakeholder"] = "Médicos Visitados";
mergetable.Rows.InsertAt(row, 11);
DataTable mergetable_Clone = mergetable.Clone(); //just copy structure, no data
for (int i = 0; i < mergetable_Clone.Columns.Count; i++)
{
if (mergetable_Clone.Columns[i].DataType != typeof(string))
mergetable_Clone.Columns[i].DataType = typeof(string);
}
foreach (DataRow datarow in mergetable.Rows)
{
mergetable_Clone.ImportRow(datarow);
}
for (int x = 1; x < mergetable_Clone.Columns.Count; x++)
{
mergetable_Clone.Rows[4][x] = mergetable_Clone.Rows[4][x] + "%";
mergetable_Clone.Rows[7][x] = mergetable_Clone.Rows[7][x] + "%";
mergetable_Clone.Rows[10][x] = mergetable_Clone.Rows[10][x] + "%";
mergetable_Clone.Rows[15][x] = mergetable_Clone.Rows[15][x] + "%";
mergetable_Clone.Rows[18][x] = mergetable_Clone.Rows[18][x] + "%";
mergetable_Clone.Rows[21][x] = mergetable_Clone.Rows[21][x] + "%";
}
MergeGrid.DataSource = mergetable_Clone;
MergeGrid.DataBind();
}
protected void MergeGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
//
//}
}
我的CSS代码
.Grid {
width: auto;
background-color: #fff;
margin: 5px 0 10px 0;
border: solid 2px #525252;
border-collapse:collapse; }
/*Gridview table data*/
.Grid td {
padding: 2px;
font-family: Calibri;
border: solid 1px #c1c1c1;
color: #000000;
text-align:right;
padding: 2px 4px 3px 4px;}
/*Gridview table header*/
.Grid th {
padding: 4px 2px;
color: #fff;
font-family:Calibri;
background: #424242 url(Images/gridheader.png) repeat-x top;
border-left: solid 1px #525252;
font-size: 95%; }
/*Gridview alternate rows*/
.Grid .alt { background: #fcfcfc url(Images/grid-alt.png) repeat-x top; }