这是我在asp.net页面中的RadGrid代码
<telerik:RadGrid ID="grvData" runat="server" GridLines="Horizontal" EnableEmbeddedSkins="false" CellPadding="0" BorderWidth="0px"
Width="1000px" Height="300px" CellSpacing="0"
OnItemCommand="grvData_ItemCommand"
OnNeedDataSource="grvData_NeedDataSource" AllowPaging="True" AllowSorting="True" Skin="skn_RadGridCustom"
SkinsDir="|CurrentTheme|/" SkinsPath="|CurrentTheme|/" >
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView PageSize="10"
AllowFilteringByColumn="false" AutoGenerateColumns="False" DataKeyNames="Id" AllowSorting="True">
<Columns>
<telerik:GridBoundColumn DataField="Id" DataType="System.Int64" ReadOnly="True" UniqueName="Id" Display="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DetailId" DataType="System.Int64" ReadOnly="True" UniqueName="DetailId" Display="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn FilterControlAltText="Filter Reject column" UniqueName="Reject" HeaderText="Reject" Display="true">
<ItemTemplate>
<telerik:RadButton ID="btnReject" runat="server" ButtonType="StandardButton" Text="Reject" CommandName="Reject" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
如何在加载网格时从Databound到RadGrid的存储过程中显示基于列IsCancelled = 1/0的启用/禁用模式的拒绝按钮。
答案 0 :(得分:0)
请尝试使用以下代码段。
ASPX.CS 请订阅&#34; ItemDataBound&#34;你的radgrid事件。
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
RadButton btnReject = item.FindControl("btnReject") as RadButton;
if (item.GetDataKeyValue("IsCancelled").ToString() == "1")
{
btnReject.Enabled = true;
}
else
{
btnReject.Enabled = false;
}
}
}
<强> ASPX 强> 要访问“IsCancelled”&#39;字段转换为C#代码请将此字段指定为datakey。
<MasterTableView DataKeyNames="Id,IsCancelled">
如果有任何疑虑,请告诉我。