This is a migrated thread and some comments may be shown as answers.

how to manipulate a CommandItemTemplate button on its own click

4 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nabeel
Top achievements
Rank 1
Nabeel asked on 26 Oct 2015, 01:54 PM

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

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 29 Oct 2015, 06:28 AM
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
0
Nabeel
Top achievements
Rank 1
answered on 29 Oct 2015, 07:28 AM
But the button needs to take actions against a particular ID (or any field within DataKeys of that particular row)
0
Nabeel
Top achievements
Rank 1
answered on 29 Oct 2015, 07:34 AM
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)
0
Eyup
Telerik team
answered on 02 Nov 2015, 04:31 PM
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
Tags
Grid
Asked by
Nabeel
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Nabeel
Top achievements
Rank 1
Share this question
or