Asp.net 如何识别RadListBox中ItemTemplate中LinkButton的CommandName
我在radlistbox中添加了一个itemtemplate,还添加了一个标签和两个链接按钮…Asp.net 如何识别RadListBox中ItemTemplate中LinkButton的CommandName,asp.net,telerik,itemtemplate,radlistbox,Asp.net,Telerik,Itemtemplate,Radlistbox,我在radlistbox中添加了一个itemtemplate,还添加了一个标签和两个链接按钮… 我的radlistbox如下所示: <telerik:RadListBox ID="RadlbOfImageGroup" runat="server" DataKeyField="ID" DataSortField="Title" DataSourceID="sdsImagesGroup" DataTextField="Title" DataValueField="ID" Skin="B
我的radlistbox如下所示:
<telerik:RadListBox ID="RadlbOfImageGroup" runat="server" DataKeyField="ID" DataSortField="Title"
DataSourceID="sdsImagesGroup" DataTextField="Title" DataValueField="ID" Skin="BlackByMe"
EnableEmbeddedSkins="False" Width="260px" Height="365px" EmptyMessage="no rec!"
AutoPostBack="True" OnSelectedIndexChanged="RadlbOfImageGroup_SelectedIndexChanged"
CausesValidation="False">
<ItemTemplate>
<table style="width: 100%;">
<tr style="width: 100%;">
<td style="width: 64%;">
<asp:Label ID="lblTitleOfIG" runat="server" CssClass="lbl_ListBox_IG_Title" Text='<%# Eval("Title") %>'></asp:Label>
</td>
<td style="width: 18%; text-align: center;">
<asp:LinkButton ID="lbEditIG" runat="server" CausesValidation="False" CommandName="Edit"
CssClass="lb_ListBox_IG" OnClick="lbEditIG_Click">Edit</asp:LinkButton>
</td>
<td style="width: 18%; text-align: center;">
<asp:LinkButton ID="lbDeleteIG" runat="server" CausesValidation="False" CommandName="Delete"
CssClass="lb_ListBox_IG" OnClick="lbDeleteIG_Click">Delete</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadListBox>
编辑
删除
我的问题是,当我点击链接按钮时,如何检查上面代码中链接按钮的CommandName?
(我们无法访问CodeBehind中的这些链接按钮)
我知道这些链接按钮不需要CommandName/我只想知道是否可以从codebehind中读取它们?我不确定这是否是解决此问题的标准方法,但我使用的是:
For Each item In RadlbOfImageGroup.Items
Dim editbutton As HtmlGenericControl = item.findcontrol("lbEditIG")
//Do something with editbutton.CommandName
Dim deletebutton As HtmlGenericControl = item.findcontrol("lbDeleteIG")
//Do something with deletebutton.CommandName
Next
上述示例在VB.Net中,但如果您使用的是C#的话,应该可以很容易地转换为C。以下是telerik团队介绍的代码:
protected void lbDeleteIG_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
if (btn.CommandName=="Delete")
{
Response.Write("Deleted");
}
}
您好,您需要命令名做什么?我只是想知道
OnCommand
是否是一个更好的选择?嗨,我亲爱的朋友/这只是一个示例/例如,我如何从CodeBehind更改所有链接按钮的前景色?你好,MoonLight,我正在制作一个类似的东西,一个城市列表框,一个显示选定城市区域的区域列表框。现在我想编辑城市或删除。从上面我无法理解您将如何删除或编辑特定项目。你能提供一些代码吗。