簡體   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