how to manipulate a CommandItemTemplate button on its own click

5 posts, 0 answers
  1. Nabeel
    Nabeel avatar
    16 posts
    Member since:
    Sep 2015

    Posted 26 Oct 2015 Link to this post

    The scenario:

    I have a MasterTableView and it contains one DetailsTable. And the GridTableView contains a button in its CommandItemTemplate section. I want to manipulate that button programatically on its own click. For example, change its caption or visibility when it is clicked by certain user etc.

    The markup for the CommandItemTemplate is below:

    <CommandItemTemplate>
                                    <div style="padding: 5px 5px; text-align:right" >
                                        <asp:Button ID="btnSaveAction" runat="server" SkinID="Save" 
                                            CausesValidation="false" Text='​Save'  CommandName="​Save" CommandArgument='<%# Eval("ID") %>' />
                                    </div>
                                </CommandItemTemplate>​

  2. Eyup
    Admin
    Eyup avatar
    3819 posts

    Posted 29 Oct 2015 Link to this post

    Hello Nabeel,

    You can use its own OnClick or OnCommand event handlers to achieve this requirement:
    <asp:Button ... OnClick="btnSaveAction_Click" />
    C#:
    protected void btnSaveAction_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        button.Text = "Success";
    }

    Hope this helps. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Nabeel
    Nabeel avatar
    16 posts
    Member since:
    Sep 2015

    Posted 29 Oct 2015 Link to this post

    But the button needs to take actions against a particular ID (or any field within DataKeys of that particular row)
  4. Nabeel
    Nabeel avatar
    16 posts
    Member since:
    Sep 2015

    Posted 29 Oct 2015 in reply to Nabeel Link to this post

    I mean such buttons do not have CommandArgument property available to them then how can I get the ID of that particular row which is clicked. For example tha MasterTable is ​INBOX and GridTableView in details table is LegalMails which contains some rows (emails). Now there is some CommandItemTemplate (button) for GridTableView so ultimately every ​row in the INBOX table will contain a command button. If a user clicks on that command button, i want to fetch the row ID of INBOX (not LegalMails row ID)
  5. Eyup
    Admin
    Eyup avatar
    3819 posts

    Posted 02 Nov 2015 Link to this post

    Hi Nabeel,

    You can achieve this requirement using the following approach:
    protected void btnSaveAction_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        GridDataItem item = (GridDataItem)button.NamingContainer;
     
        // I assume this event handler would be raised
        // for the detail table button
        string value = item.GetDataKeyValue("LegalMails").ToString();
        button.Text = value;
    }

    Looking forward to hearing from you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top