-6ren">
gpt4 book ai didi

c# - 如何调用rad网格的命令

转载 作者:行者123 更新时间:2023-12-03 06:45:53 25 4
gpt4 key购买 nike

我有一个带有以下代码的 rad 网格

 <telerik:GridTemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="Delete" Text="Remove &raquo"
CommandArgument='<%# Eval("ApartmentId") %>'
CommandName="RemoveItem" CssClass="Button" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>

.CS代码如下

protected void radGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Page")
{
}
else
{
if (e.CommandName == "RemoveItem")
{
Apartments apartAdmin = new Apartment();
bool deleted = apartAdmin.Delete(int.Parse(e.CommandArgument.ToString());
if (deleted)
{
radGrid.Rebind();
}
}
}
}

我的问题是,当我调试它时,假设我向该事件添加断点,它永远不会被触发,就像它由于某种原因没有看到该事件一样......任何人都可以看到问题可能是什么?这是顶部网格的标记

 <telerik:RadGrid ID="radGrid" ShowFooter="true" ShowHeader="true" CaptionAlign="Left"
runat="server" ForeColor="Black" CellPadding="4" AutoGenerateColumns="False"
CssClass="Grid" Width="100%" GridLines="None" OnRowCommand="radGrid_RowCommand"
OnNeedDataSource="radGrid_NeedDataSource" AllowPaging="True" AllowSorting="true">
<MasterTableView DataKeyNames="ApartmentID,ApartmentTypeID">
<CommandItemSettings ShowRefreshButton="true" ShowAddNewRecordButton="false" />
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="Delete" Text="Remove &raquo"
CommandArgument='<%# Eval("ApartmentId") %>'
CommandName="RemoveItem" CssClass="Button" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<NoRecordsTemplate>
No related items found</NoRecordsTemplate>
</MasterTableView>
<FooterStyle CssClass="FooterStyle" />
<ItemStyle CssClass="RowStyle" />
<HeaderStyle CssClass="HeaderStyle" />
<AlternatingItemStyle CssClass="AlternatingRowStyle" />
<PagerStyle CssClass="PagerStyle" FirstPageText="First" LastPageText="Last" Mode="NextPrevAndNumeric"
AlwaysVisible="true" />
</telerik:RadGrid>

最佳答案

您在项目模板中有一个链接按钮,在链接按钮本身上添加一个 OnClick 处理程序,该事件肯定会被触发。

例如:

protected void LinkButton1_Click(Object sender, EventArgs   
{
LinkButton button = sender as LinkButton;
Apartments apartAdmin = new Apartment();
bool deleted = apartAdmin.Delete(int.Parse(button.CommandArgument.ToString());
if (deleted)
{
radGrid.Rebind();
}

}

关于c# - 如何调用rad网格的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8393039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com