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

How do you add a custom button?

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MissioDei
Top achievements
Rank 1
MissioDei asked on 29 Aug 2010, 01:32 AM
How do you add a custom button to a column?

I've been searching the website and found a few things that are close to what I'm trying to do. I'm still pretty new to all this, and didn't completely understand it.

I have a Rad Grid pulling in registration data from a database. I want to add another column that contains a button that will call an "unregister Event". On the click event, I want to right code that unregisters the user.

What is the most efficient way to get this done?

Thanks in advance for any help.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Aug 2010, 07:21 AM
Hello,


You can either use the GridButtonColumn or GridTemplateColumn with Button inside. Then set the CommandName for the column/button and check for the CommandName in ItemCommand event.

Using ButtonColumn:
<telerik:GridButtonColumn CommandName="unregister" Text="Unregister ">
</telerik:GridButtonColumn>


Using TemplateColumn:
<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:Button ID="Button1" CommandName="unregister" runat="server" Text="Unregister" />
    </ItemTemplate>
</telerik:GridTemplateColumn>



-Shinu.
0
MissioDei
Top achievements
Rank 1
answered on 30 Aug 2010, 01:54 PM
<telerik:GridButtonColumn ButtonType="PushButton" CommandName="Unregister" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to unregister?" ConfirmTitle="Unregister Confirmation" HeaderButtonType="TextButton" Text="Unregister" UniqueName="Unregister">
</telerik:GridButtonColumn>

I had gotten this far.

How do I create a click event for the button in the codebehind? I'm assuming I have to "find" the button first and would the click event be something like:

RadGrid1_Unregister

Thanks again for answering my question, any further help would be appreciated.

0
Iana Tsolova
Telerik team
answered on 02 Sep 2010, 11:08 AM
Hello Strategon,

You can handle the button command in the grid ItemCommand server-side event:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if(e.CommandName == "Unregister")
    {
        GridDataItem currentItem = e.Item as GridDataItem;
        //your code here
    }
}


Regards,
Iana
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
MissioDei
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
MissioDei
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or