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

Select Row and Enter in a Server Side Code

5 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lupotana
Top achievements
Rank 1
lupotana asked on 12 Oct 2009, 03:06 PM

Hi, I've a small problem with RadGrid.
I must transform old code with ASP.NET GridView in a new code with Telerik RadGrid.

In old version I've two TemplateField in my GridView : in first column  there is a label with the code of row (hide) and in the second column there is an ImageButton with an Handler with the function btnUpdate_Click.

....

<asp:TemplateField Visible="false">  
 <ItemTemplate> 
         <asp:Label ID="lblCode" runat="server" Text='<%# Bind("Code") %>' /> 
        </ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField> 
 <ItemTemplate> 
         <asp:ImageButton ID="btnEdit" runat="server"  ImageUrl="~/edit.png" OnClick="btnEdit_Click" CausesValidation="false" /> 
 </ItemTemplate> 
</asp:TemplateField> 

......

In function btnEdit_Click I cast the row and the Label control in the row and with the code I transfer the page.

protected void btnEdit_Click(object sender, EventArgs e)  
{  
 GridViewRow row = ((GridViewRow)((ImageButton)sender).NamingContainer);  
 Label lblCode = (Label)row.Cells[0].Controls[1];  
 Server.Transfer("~/Detail.aspx?Code="+lblCode.Text);  

How do I do this operation with RadGrid?
I don't want use the the Inline solution or client scripts.
I need that when the user click on an imageButton or button in a row I enter in a server side code.

Thanks,
Marco

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2009, 05:17 AM
Hello Marco,

You can try out the following code to access the label in a TemplateColumn on clicking a button inside another TemplateColumn:
c#:
 protected void btnEdit_Click(object sender, ImageClickEventArgs e) 
    { 
        GridDataItem row = ((GridDataItem)((ImageButton)sender).NamingContainer); 
        Label lblCode = (Label)row.FindControl("lblCode"); 
        Server.Transfer("~/Detail.aspx?Code=" + lblCode.Text);   
    } 

Also go through the following help document which you may find helpful:
Accessing cells and rows

Thanks
Princy.
0
lupotana
Top achievements
Rank 1
answered on 13 Oct 2009, 08:29 AM
My problem is not the server code... the problem is that in RadGrid don't have a Template Column.
How I manage an event click in an imagebutton in the row ?

For example : a Row have an image for the update and an image for the delete.
I don't want use the example of telerik..
I want that after click the imagebutton I enter in a server code with the index row slected.

Is possible ?
0
Tsvetoslav
Telerik team
answered on 16 Oct 2009, 07:39 AM
Hi lupotana,

RadGrid does have a template column and it is called GridTemplateColumn:
http://www.telerik.com/help/aspnet-ajax/grdcolumntypes.html

In addition, the solution Princy has offered is the valid one in your case.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
lupotana
Top achievements
Rank 1
answered on 05 Mar 2014, 06:53 PM
Hi, with new versions of Telerik I able to do this operation.
Now my question is : Server.Transfer work if I not use RadGrid with RadAjaxManager. Is not possible use Ajax with Server.Transfer ?


protected void gvList_SelectedIndexChanged(object sender, EventArgs e)
 {
 GridItem row = gvList.SelectedItems[0];
 HttpContext.Current.Items.Add("Operation", EventContext.Update.ToString());
 HttpContext.Current.Items.Add("CustomerCode", row.Cells[2].Text);
 Server.Transfer("~/Desktop/Function/Customer/CustomerDetail.aspx");
}

 
sdsd
0
Maria Ilieva
Telerik team
answered on 10 Mar 2014, 12:23 PM
Hello Marco,

Basic server transfer couldn't be achieved during Ajax request. I would suggest you to revise the discussion below for more information on possible alternative approaches:
http://stackoverflow.com/questions/9893433/ajax-enabled-update-progress-bar-on-server-transfer

Regards,
Maria Ilieva
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Tags
Grid
Asked by
lupotana
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
lupotana
Top achievements
Rank 1
Tsvetoslav
Telerik team
Maria Ilieva
Telerik team
Share this question
or