Telerik 如何以编程方式格式化radgrid单元
我必须根据单元格的值设置radgrid单元格的格式(背景色、前景色、字体样式) 比如说 如果该值为负值,则将该单元格的前颜色设置为红色Telerik 如何以编程方式格式化radgrid单元,telerik,radgrid,cell-formatting,Telerik,Radgrid,Cell Formatting,我必须根据单元格的值设置radgrid单元格的格式(背景色、前景色、字体样式) 比如说 如果该值为负值,则将该单元格的前颜色设置为红色 有谁能告诉我如何做到这一点吗?在您的aspx页面的radGrid声明中添加一行onItemDataBound=“Data\u onItemDataBound” 然后将其添加到代码隐藏中。单元格[]中的数字是要修改或验证的列的索引 protected void Data_OnItemDataBound(object sender, GridItemEventArg
有谁能告诉我如何做到这一点吗?在您的aspx页面的radGrid声明中添加一行onItemDataBound=“Data\u onItemDataBound” 然后将其添加到代码隐藏中。单元格[]中的数字是要修改或验证的列的索引
protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToDecimal(item.Cells[3].Text) < 0)
{
item.Cells[3].ForeColor = System.Drawing.Color.Red;
}
}
}
受保护的无效数据\u onitemdata绑定(对象发送方,GridItemEventArgs e)
{
if(e.Item为GridDataItem)
{
GridDataItem=(GridDataItem)e.item;
if(Convert.ToDecimal(item.Cells[3].Text)<0)
{
item.Cells[3]。前景色=System.Drawing.Color.Red;
}
}
}
受保护的void grdName\u ItemDataBound(对象发送方,GridItemEventArgs e)
{
if(e.Item为GridDataItem)
{
GridDataItem=(GridDataItem)e.item;
if(Convert.ToInt32(((DataRowView)item.DataItem)[“Column”])
以下代码可用于RadGrid中的所有单元
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;
}
}
}
protectedvoid RadGrid\u ItemDataBound(对象发送方,GridItemEventArgs e)
{
foreach(RadGridProduct.MasterTableView.Items中的GridDataItem数据项)
{
int cellCount=dataItem.Cells.Count;
foreach(dataItem.Cells中的GridTableCell项)
{
if(item.Text==null | | Convert.ToInt32(item.Text)<0)
item.BackColor=System.Drawing.Color.Brown;
}
}
}
我不知道为什么有人否决了我,我的答案与其他人不同,所以我想我应该加上它。也许他们不喜欢桃泡芙
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;
}
}
}