Domanda

I added an itemtemplate to my radlistbox and also added one label and two linkbutton(s) in it ...
my radlistbox is like below :

<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>

My Problem is how can I check the CommandName of LinkButtons in code above when I click on them? (We don't have access to these LinkButtons in CodeBehind)

I know we do not need CommandName for those LinkButtons / I Just want to know is it possible to read them from codebehind?

È stato utile?

Soluzione 2

here is the code that has been introduced by telerik team :

protected void lbDeleteIG_Click(object sender, EventArgs e)
   {
       LinkButton btn = sender as LinkButton;
       if (btn.CommandName=="Delete")
       {
           Response.Write("Deleted");
       }
   }

Altri suggerimenti

I'm not sure if this is a standard way of addressing this issue but it's what I use:

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 

The above example is in VB.Net but should translate fairly easily to C# if that's what you're using.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top