问题描述
我有一个BooundColumn在我Telerik的radgrid控件象下面这样:
i have a BooundColumn in my telerik RadGrid like below :
<telerik:GridBoundColumn DataField="Status" FilterControlAltText="Filter Status column"
HeaderText="Status" SortExpression="Status" UniqueName="Status"
FilterImageToolTip="Filter">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridBoundColumn>
在我的SQL Server状态栏2008数据库可以接受空值和radgrid控件显示他们有一个空字符串。结果
我怎么能代替这些空字符串
与可着色字符串
?结果
更换意味着像这样的东西 - > &LT;跨度风格=颜色:红色;'&GT;空&LT; / SPAN&GT;
我知道我可以在绑定列转换为TemplateColumn中是这样的:
Status Column in my sql server 2008 database can accept null values and RadGrid shows them with an empty string.
how can i replace these Empty Strings
with a Colorable Strings
?
mean replacement with something like this -> <span style='color: red;'>Empty</span>
i know i can convert that BoundColumn to TemplateColumn like this :
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Status column"
HeaderText="Status" UniqueName="TemplateColumn_Status" FilterImageToolTip="Filter"
ReadOnly="False" Visible="False">
<ItemTemplate>
<asp:Label ID="lblStatusInsideGrd" runat="server" Font-Size="11px" Text='<%# (bool)Convert.IsDBNull(Eval("Status")) ? "<span class=\"lblInsideGrd\">Empty</span>" : Eval("Status") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridTemplateColumn>
这是更换一个好主意,和伟大工程。但这样做,我失去radgrid控件 Filering
在此列。结果
请你简易淋浴我保持radgrid控件Friltering另一种方式?
this replacement is a good idea and works great. but by doing that i lose RadGrid Filering
on this column.
would you please showe me another way with keeping RadGrid Friltering?
在此先感谢
推荐答案
您可以这样做的ItemDataBound事件,当网格绑定到的SqlDataSource在你的情况,你可以得到当前的DataRow:
You could do that on ItemDataBound event, when grid is binded to SqlDataSource as in your case you can get current DataRow :
更新:我只是阔叶树code,与DataRow的作品,并修正在列的背景设定
Update: I leaved just code that works with DataRow, and fix column background setting
public void TestGrid_ItemDataBound(Object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
if (e.Item.DataItem is DataRowView)
{
GridDataItem gdItem = (GridDataItem)e.Item;
DataRow rw = ((DataRowView)e.Item.DataItem).Row;
if (rw.IsNull("Status"))
{
GridColumn urlColumn = TestGrid.MasterTableView.Columns.FindByUniqueName("Status");
gdItem.Cells[urlColumn.OrderIndex].BackColor = Color.Red;
gdItem["Status"].Text = "Empty";
}
}
}
}
编辑由提问者结果
真的感谢这些codeS。结果
在codeS下面都ok我:
EDIT BY QUESTIONER
Really thanks for these codes.
the codes below are ok for me :
protected void grdSMS_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (item["Status"].Text == " ")
{
item["Status"].ForeColor = Color.Red;
item["Status"].Text = "Empty";
}
}
}
这篇关于如何处理空值(列)在Telerik的radgrid控件? (替换为HTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!