Telerik RadGrid GridButtonColumn不作为Button显示

时间:2016-08-24 09:00:48

标签: c# asp.net telerik radgrid

“拒绝”不显示按钮。相反,它显示为纯文本。以下是我用过的代码。

<telerik:RadGrid ID="grvUpdate" runat="server" GridLines="Horizontal"
    CellPadding="0" BorderWidth="0px" EnableEmbeddedSkins="False"         
    Width="382px" CellSpacing="0">
    <MasterTableView
        AllowPaging="true"
        PageSize="15"
        CommandItemDisplay="Top"
        AllowFilteringByColumn="false" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Id">

        <Columns>
            <telerik:GridBoundColumn DataField="Id" DataType="System.Int64" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name">
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Amount" HeaderText="Amount" SortExpression="Amount" UniqueName="Amount">
            </telerik:GridBoundColumn>                   
            <telerik:GridButtonColumn ButtonType="PushButton" HeaderText="Reject" Text="Reject" UniqueName="Reject" CommandName="Reject"></telerik:GridButtonColumn> 
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

请您告诉我上述代码需要做哪些更改才能正确显示按钮。

3 个答案:

答案 0 :(得分:0)

由于您设置了EnableEmbeddedSkins="False"GridButtonColumn可能无法以正确的方式呈现。

您可以做的是将自定义CSS应用于GridButtonColumn,并按照您想要的方式设置样式。

<telerik:GridButtonColumn ButtonType="PushButton" HeaderText="Reject" Text="Reject" UniqueName="Reject" CommandName="Reject" ButtonCssClass="YOUR CUSTOM CSS CLASS"></telerik:GridButtonColumn> 

替代方法

<telerik:GridButtonColumn ButtonType="PushButton" HeaderText="Reject" Text="Reject" UniqueName="Reject" CommandName="Reject"></telerik:GridButtonColumn>

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
{ 
    if (e.Item is GridDataItem) 
    { 
        var dataItem = (GridDataItem)e.Item; 
            (dataItem["Reject"].Controls[0] as Button).CssClass = "MyButtonStyle"; 
    } 
}

<style type="text/css"> 
    .MyButtonStyle 
    { 
        background-color:black !important;
        color:white!important;
    } 
</style> 

使用自定义模板

<telerik:GridTemplateColumn>
       <ItemTemplate>
           <asp:Button ID="btnReject" runat="server" CommandName="Reject"  CommandArgument='<%# Eval("Id") %>'/>
       </ItemTemplate>
 </telerik:GridTemplateColumn>

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == "Reject")
       {
           var Id = e.CommandArgument.ToString();
           // do something...
       }
   }

答案 1 :(得分:0)

以下代码适用于我

<telerik:GridTemplateColumn FilterControlAltText="Filter Reject column" UniqueName="Reject" HeaderText="Reject" Display="true">
                    <ItemTemplate>
                        <telerik:RadButton ID="Button1" runat="server" ButtonType="StandardButton" Text="Reject" CommandName="Reject" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

答案 2 :(得分:0)

如果您的radgrid始终处于EditForm模式,请确保该列的ShowInEditForm属性设置为true。