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

发布于 2024-12-18 02:10:35 字数 97 浏览 1 评论 0原文

我有一个 Radgrid,它具有来自数据库查询的动态数据绑定字段,并且每次它们都不同。现在,当此数据显示在网格上时,我想将 0 的单元格的值更改为“”或“”。

谢谢

I have a Radgrid who has Dynamic Databound fields which comes from a database query and each time they are different. Now when this data is displayed on the GRID, i want to change the value of Cells where its 0 to " " or "."

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-12-25 02:10:35

您需要挂钩 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

You need to hook into the CellFormatting event. Here you can check the value of the cell and change it as required.

Something along the lines of:

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
水波映月 2024-12-25 02:10:35
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)
{ }
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)
{ }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文