![](/img/trans.png)
[英]Add RequiredFieldValidator to dynamically created control in code behind
[英]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.