我在ASP.Net中有一个网格视图,其格式如下:
Col1 | Col2 | Col3 | ...... |Col200
-----------------------------------
Row1 | | | |
-----------------------------------
Row2 | | | |
-----------------------------------
Row3 | | | |
-----------------------------------
.
.
-----------------------------------
Row600| | | |
命名的列在表1中,行名称在表2中。我制作了两个单独的数据适配器和数据集,一个用于列名,一个用于行名,并将Gridview列与Table1绑定,将Gridview行与Table2绑定。GrdView中的其余单元格为空。
在空单元格上,我想显示另一个表中的一些数据。我怎样才能做到这一点?任何想法将不胜感激。
使用网格视图的OnRowDataBound
事件来拦截绑定到网格中每一行的数据,并检查单元格值以查看其是否为空,如下所示:
后台代码:
protected void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
// Only work with data rows, ignore header and footer rows
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Check if value in cell is empty here
// For example use the RowIndex property to check for row #2
if(e.Row.RowIndex == 2)
{
// Change text to X in cell 4
e.Row.Cells[3].Text = "X";
}
// If so, then go to other table and retrieve value here
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句