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

auto generatet edit/delete column

6 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gernot
Top achievements
Rank 1
Gernot asked on 03 Jul 2008, 09:12 AM
Hello,
i create a RadGrid from Code. All Columns are auto generated.
 
1. how can i change the button types of auto generatet "edit/delete" columns to "ImageButton"?

2. Is it posible to position the command buttons on the right site of the DataBound Columns?

Many thanks for your great support ;-)

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jul 2008, 10:15 AM
Hi,

Try the following code snippet to achieve the desired scenario.

CS:
   protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column is GridEditCommandColumn) 
        { 
            GridEditCommandColumn editcol = (GridEditCommandColumn)e.Column; 
            editcol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton; 
            editcol.ItemStyle.HorizontalAlign = HorizontalAlign.Right; 
            
        } 
       if(e.Column is GridButtonColumn) 
       { 
             GridButtonColumn deletecol = (GridButtonColumn)e.Column; 
             if (deletecol.UniqueName == "AutoGeneratedDeleteColumn") 
             { 
                 deletecol.ButtonType = Telerik.WebControls.GridButtonColumnType.PushButton; 
                 deletecol.ItemStyle.HorizontalAlign = HorizontalAlign.Right; 
             } 
       } 
             
   } 

Thanks
Princy.
0
Gernot
Top achievements
Rank 1
answered on 04 Jul 2008, 08:00 AM
Hi,
thank you for your help.

Is it not posible to set any property of the radgrid to archive this?

Cheers
0
Gernot
Top achievements
Rank 1
answered on 04 Jul 2008, 11:21 AM
Hi,
the example you wrote did not work.
Maybe you have an older version of radcontrols!

This worked for me but the command columns are still on the left side:


           if (e.Column is Telerik.Web.UI.GridEditCommandColumn)
            {
                Telerik.Web.UI.GridEditCommandColumn editcol = (Telerik.Web.UI.GridEditCommandColumn)e.Column;
                editcol.ButtonType = Telerik.Web.UI.GridButtonColumnType.ImageButton;
                editcol.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;

            }
            if (e.Column is Telerik.Web.UI.GridButtonColumn)
            {
                Telerik.Web.UI.GridButtonColumn deletecol = (Telerik.Web.UI.GridButtonColumn)e.Column;
                if (deletecol.UniqueName == "AutoGeneratedDeleteColumn")
                {
                    deletecol.ButtonType = Telerik.Web.UI.GridButtonColumnType.ImageButton;
                    deletecol.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                }
            } 

Cheers
Alaeddin
0
Pavel
Telerik team
answered on 07 Jul 2008, 12:10 PM
Hi Alaeddin,

If I understand you correctly, you want the Edit column to be displayed last in the Grid? You can achieve this by swapping it with the last one using the PreRender event handler of the Grid. Here is a snippet:
protected void RadGrid1_PreRender(object sender, EventArgs e)  
{  
    RadGrid1.MasterTableView.SwapColumns(2, 9);  

The second parameter is the index of your last column (note that column indexes start at 2 as explained here).

I have attached a sample for reference.

Regards,
Pavel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Gernot
Top achievements
Rank 1
answered on 08 Jul 2008, 09:49 AM
Hello Pavel,
this did not work for me because my gridview is generated from code.
My autogenerated gridview has only 2 columns in the "PreRender" event.

In your example the gridview is on the page.

:-(

Many Thanks
0
Pavel
Telerik team
answered on 09 Jul 2008, 11:58 AM
Hi Alaeddin,

The approach for a programmaticaly created Grid is basically the same. Please find the attached project for reference.

All the best,
Pavel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Gernot
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gernot
Top achievements
Rank 1
Pavel
Telerik team
Share this question
or