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

GridButtonColumn CommandArgument problem

2 Answers 403 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luc
Top achievements
Rank 1
Luc asked on 15 Jan 2009, 04:42 PM
Hello,

I need to set the CommandArgument of a GridButtonColumn so it can be processed client-side.  I tried to use the approach described at http://www.telerik.com/community/forums/aspnet-ajax/grid/commandargument.aspx but it doesn't seem work.

My GridButtonColumn definition is :
<telerik:GridButtonColumn CommandName="ConfigSl" Text="Configure SiteLink" UniqueName="ConfigSlBtn">                   </telerik:GridButtonColumn>

My CodeBehind argument setter is :
      protected void rgSite_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
      {
         GridDataItem item = e.Item as GridDataItem;
         if (item != null)
         {
            string site = item.GetDataKeyValue("Code") as string;

            LinkButton link = (LinkButton)item["ConfigSlBtn"].Controls[0];
            link.CommandArgument = site;
         }         
      }

My client-side Javascript, for now, is :
        function RadGridCommand(sender, args)
        {
            var commandName = args.get_commandName();
            var commandArgs = args.get_commandArgument(); 

            var result = String.format("CommandName: {0}, CommandArgument: {1}", commandName, commandArgs); 
            alert( result );
            
            if ( commandName == 'ConfigSl' )
            {
                args.set_cancel( true );
            }
        }

The commandArgs value I get for this is the row number, not the value set into the "Code" key.  Also, I checked through the debugger and the Site variable into the ItemCreated event has the right value.

What am I doing wrong?

Thanks

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 19 Jan 2009, 09:04 AM
Hello,

In order to programmatically change argument of command button when client-side command event is used, you should change button's client click function to generate different client-side click handler. This can be achieve by using GridDataItem's ClientFireCommandFunction method, which will generate the needed syntaxis automatically. Thus the code should look similar to the following:

 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem dataItem = ((GridDataItem)e.Item);  
            LinkButton button = dataItem["ButtonColumn"].Controls[0] as LinkButton;  
            button.OnClientClick = dataItem.ClientFireCommandFunction(button.CommandName, "MyNewCommandArgument");  
        }  
    } 

Please give it a try and let us know if this helps.
 
Sincerely yours,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Luc
Top achievements
Rank 1
answered on 20 Jan 2009, 12:54 AM
It worked great!

Thank you very much
Tags
Grid
Asked by
Luc
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Luc
Top achievements
Rank 1
Share this question
or