How do I (1) add two buttons in one column (2) code custom button event click logic.

2 posts, 0 answers
  1. Greg
    Greg avatar
    16 posts
    Member since:
    Sep 2013

    Posted 08 Jan 2014 Link to this post

    I've  been looking for an example of adding more than one button to a single radGrid column.  Is this possible?  I have not found an example of that.  Also, I am looking for an example of where you can add a button to the grid column, but not for add, delete, edit, etc. but for a custom usage.  Is that possible? 

    What I am doing....

    I have a grid that list about 400 records that will be used to generate a complex report.  The report takes 30+ minutes to generate so I want the users to be able to use the grid to perform a quick test on just the row/record without having to run the whole report.

    One way to think about this is as a phonebook.  Say you have a list of 12-million names in your phonebook. Now you have a list of 400 employees that you have listed in a grid and you want to get the phone numbers and emails for and generate an office phonebook.  But say that repot takes 1hour to run.  That is fine to run every few months and generate your office phonebook list, but what if you only needed to look up 1 phone number?  You do not want to run the whole phonebook that takes an hour.  You just want to do a quick search and display the phone number for that one row in the grid.  So that is sort of what I am running into. 

    So my grid is sort of like that, where the rows in the grid are the individuals that you do not have phone numbers or emails for.  I want the users to be able to click a button to look up their email or phone number.  I think way to do this is to have two image buttons and when the users clicks a button, I want to fire off my unique logic and in an empty column that is last in the grid, display the phone number or email for that user.  That way the users could run down a list of 10 or 15 of them and the email and phone number would remain in the grid.

    I want to use Ajax to perform the search.

    Yes, a phonebook is a lame example. But it's a good anolgy as to what I am doing. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Jan 2014 Link to this post

    Hi Greg,

    You can use GridTemplateColumn to obtain your required scenario. Below is a sample code that i tried in which i added two Image-buttons and on its click event I'm Displaying the values in the next column.

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
                <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID">
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />           
                        <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" ToolTip="Get Details" />
                        <asp:ImageButton ID="ImageButton2" runat="server" OnClick="ImageButton2_Click" />
                        <asp:Label ID="Label1" runat="server"></asp:Label>

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        ImageButton imgbtn = (ImageButton)sender;
        GridDataItem data = (GridDataItem)imgbtn.NamingContainer;
        string id = data["ID"].Text; // Get the ID column value
        string name = data["Name"].Text; // Get the Name column value
        Label lbl = (Label)data.FindControl("Label1");
        lbl.Text ="ID="+ id + " Name=" + name; Display it on the Next column which is a TemplateColumn with Label
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        //Your code

    Please try and let me know if any concern.
  3. DevCraft R3 2016 release webinar banner
Back to Top