Telerik RadGrid GridButtonColumn 作为按钮不可见
Telerik RadGrid GridButtonColumn not visible as Button
拒绝按钮不可见。相反,它显示为纯文本。下面是我使用的代码。
<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>
能否请您告诉我需要对上述代码进行哪些更改才能使按钮正确可见。
由于您设置了 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...
}
}
下面的代码适合我
<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>
如果您的 radgrid 始终处于 EditForm 模式,请确保该列的 ShowInEditForm 属性 设置为 true。
拒绝按钮不可见。相反,它显示为纯文本。下面是我使用的代码。
<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>
能否请您告诉我需要对上述代码进行哪些更改才能使按钮正确可见。
由于您设置了 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...
}
}
下面的代码适合我
<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>
如果您的 radgrid 始终处于 EditForm 模式,请确保该列的 ShowInEditForm 属性 设置为 true。