RadGrid动态数据列 - 检查每个单元格值

时间:2011-11-24 21:31:01

标签: radgrid

我有一个Radgrid,它有动态数据绑定字段,它来自数据库查询,每次都不同。现在,当这些数据显示在GRID上时,我想将其0的值更改为“”或“。”

由于

2 个答案:

答案 0 :(得分:0)

您需要挂钩CellFormatting事件。在这里,您可以检查单元格的值并根据需要进行更改。

有些事情:

Private Sub RadGrid_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGrid.CellFormatting
            if e.CellElement.RowInfo.Cells("ZeroColumn").Value = "0" then
               e.CellElement.RowInfo.Cells("ZeroColumn").Value = "."
            end if
    End Sub

答案 1 :(得分:-3)

try
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Cells[e.Row.Cells.Count - 1].Visible = false;
    }

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        for (int i = 3; i < e.Row.Cells.Count; ++i)
        {
            TextBox tb = new TextBox();
            tb.ID = "txtRow" + e.Row.RowIndex.ToString() + "Column" + i.ToString();
            tb.Width = 50;
            //if (Convert.ToBoolean(e.Row.Cells[i].Text) == false)
            //tb.Text = "0";
            //tb.Text = e.Row.Cells[i].Text;
            e.Row.Cells[i].Controls.Add(tb);
            // e.Row.Cells[i].Enabled = Convert.ToBoolean(e.Row.Cells[i].Text);
        }
        e.Row.Cells[e.Row.Cells.Count - 1].Visible = false;
    }
}
catch (Exception ex)
{ }