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

[Solved] how to Data Bind Command Argument

3 Answers 1064 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 25 Jun 2009, 08:31 PM
My ImageButton (imgbtnToggle) will not pass the CommandArgument to my method ToggleTaskResults. Based on searches here, I guess this is because I'm doing Client Side DataBinding? How can I do server side or whatever to make this work? Thanks?

 

<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="dgResults_OnItemDataBound" AutoGenerateColumns="false" EnableViewState="false" >

 

 

<MasterTableView>

 

 

<Columns>

 

 

<telerik:GridTemplateColumn>

 

 

<ItemTemplate>

 

 

<asp:ImageButton ID="imgbtnToggle" runat="server" CausesValidation="false" Visible='<%#Eval("IsTask").Equals(false) %>'

 

 

CommandArgument='<%#Eval("ResultId") %>' OnClick="ToggleTaskResults" />

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridBoundColumn DataType="System.Int32" DataField="JobId">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataType="System.Int32" DataField="ResultId">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataType="System.Boolean" DataField="IsTask">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

</ContentTemplate>

 

 

</asp:UpdatePanel>

 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Jun 2009, 08:36 AM
Hello Joel,

The click handler for the image button control does not accept a command argument parameter. The correct approach to this scenario is, as follows:

1. Attach an event handler to RadGrid's ItemCommand event.
2. Specify a value for the CommandName property of the image button.
3.In the ItemCommand handler check for this command name to make sure the command is triggered by the image button.
4. Use the event arguments object to extract the CommandArgument passed from the button - the latter is contained in the  e.CommandArgument property.

I hope this information helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
FNZ N
Top achievements
Rank 1
answered on 29 Oct 2009, 07:55 AM
i set a Column Name for CommandArgument for a button in radgrid.
but when i request e.commandArgument in ItemComamnd event  it return exactly the name of Column not the value of Column.
for example 'id' instead of '4' or '5' ?
how can i solve this problem ?
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2009, 08:24 AM
Hi,

Setting the datafield directly to the CommandArgument  without binding it will be considered as a string. So you should be binding the CommandArgument property to the field name using Eval syntax to retrieve the  corresponding  field values. Here's an example:
aspx:
<asp:Button ID="Button1" runat="server" CommandArgument='<%#Eval("DataFieldName")%>' Text="Button"/> 

Hope this helps..
Princy.
Tags
Grid
Asked by
Joel
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
FNZ N
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or