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

Convert ASP.Net Gridview column to RadGrid

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 16 Jun 2011, 07:43 PM
Here is the column in my ASP.Net Gridview that is working:

<

 

asp:TemplateField>

 

 

<ItemTemplate>

 

 

<asp:LinkButton runat="server" ID="lbtn1" CommandName="cmd1" CommandArgument='<%#Eval("id")%>' Text="View Sections" />

 

 

</ItemTemplate>

 

 

</asp:TemplateField>

The event is called and processed (the method called is 'protected void gv_RowCommand(Object sender, GridViewCommandEventArgs e)' and it assigns the ID to sqldatasource on the page for another use).

 


How do I implement this in a RadGrid and have it call a method in the code behind to pass the value to the other sqldatasource?

Thanks

1 Answer, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 16 Jun 2011, 09:22 PM
Here is how I solved it piecing together from many other forum posts:

In the opening grid tag, use the OnItemCommand:

<

 

telerik:RadGrid ID="rg1" runat="server" DataSourceID="sdsTest"

 

 

AutoGenerateColumns="False" CellSpacing="0" GridLines="None" OnItemCommand="rg1_ItemCommand">

The column for the RadGrid:

 

 

<telerik:GridButtonColumn

 

 

 

 

 

CommandName="cmd1" FilterControlAltText="Filter column2 column"

 

 

Text="View Sections" UniqueName="lbtnID" CommandArgument="">

 

 

 

 

 

</telerik:GridButtonColumn>

 

 

 

Please note that in my situation, the CommandName value did not matter nor did the CommandArgument. Depending on the complexity of your column and need, you may need those values.

In your code behind call that event:

 

 

protected void rg1_ItemCommand(object sender, GridCommandEventArgs e)

 

{

 

if (e.Item is GridDataItem)

 

{

 

GridDataItem item = (GridDataItem)e.Item;

 

 

 

 

sds2.SelectParameters[

"id"].DefaultValue = item.GetDataKeyValue("id").ToString();

 

rg2.Visible =

true;

 

}

}

 

 

If it helps anyone else, the differences between my use of the ASP.Net Gridview and RadGrid were that the ASP.Net Grid
used "OnRowCommand" in the Grid tag and the code behind event used _RowCommand(Object sender, GridViewCommandEventArgs e)

Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Share this question
or