繁体   English   中英

如何在后面动态创建的radgrid代码中添加Cell Formatting事件方法?

[英]How to add Cell Formatting event method to dynamically created radgrid code behind?

我已经在后面的代码上创建了rad网格。 现在,我想向其添加单元格格式化事件。 我该如何实现?

       RadGrid grid = new RadGrid();
        grid.ID = "rdggrid";

        grid.Skin = "Metro";
        grid.Width = Unit.Percentage(100);            
        grid.PageSize = 15;
        grid.AllowPaging = true;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;          


        grid.MasterTableView.Width = Unit.Percentage(100);

        grid.ClientSettings.Resizing.AllowColumnResize = true;
        grid.ClientSettings.Resizing.ResizeGridOnColumnResize = true;
        grid.ClientSettings.Resizing.AllowResizeToFit = true;

        grid.ItemDataBound += new GridItemEventHandler(RadGrid_ItemDataBound);

我想添加此方法

void radGrid_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)     
{     

}

用于WinForms的RadGridView不同,用于ASP.NET AJAX(WebForms)的RadGrid不提供CellFormatting服务器端事件。 您可以将RadGrid的ItemDataBound事件用于ASP.NET AJAX来设置单元格的样式:

 protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
            {
                TableCell cell = item["Column"];
                cell.BackColor = Color.PeachPuff;
            }
        }
    }

要么

protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        foreach (GridDataItem dataItem in RadGridProduct.MasterTableView.Items)
        {
            int cellCount = dataItem.Cells.Count;

            foreach (GridTableCell item in dataItem.Cells)
            {
                if (item.Text == null ||Convert.ToInt32(item.Text) < 0 )
                    item.BackColor = System.Drawing.Color.Brown;
            }

        }

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM