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

[Solved] How to toggle hyperlink for whole row?

6 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alec
Top achievements
Rank 1
Alec asked on 06 May 2009, 07:23 AM
Apparently, I have a template column for edit link, but is there a way I can make the whole row clickable so that when i click on a row, it goes to a page that i want it go to?

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 May 2009, 09:08 AM
Hello Alec,

You can use the RowClick command of the grid as shown below and redirect to another page. Also set the EnablePostBackOnRowClick property of the grid to true.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server"  OnItemCommand="RadGrid1_ItemCommand">            
  <ClientSettings EnablePostBackOnRowClick="true" > 
  </ClientSettings> 

c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick") 
        { 
            Response.Redirect("EditForm.aspx"); 
        } 
    } 

Thanks
Princy.
0
Alec
Top achievements
Rank 1
answered on 06 May 2009, 11:48 PM
Great, but how can I access the data item?

I tried e.Item.DataItem but it's null. I need that as the edit page needs the row id.
0
Princy
Top achievements
Rank 2
answered on 07 May 2009, 04:51 AM
Hello Alec,

DataItem is null after a post-back and so this object would be available only during data-binding. But rather you can access the data item and pass its index as shown below:
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick" && e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            int index = dataItem.ItemIndex; 
            Response.Redirect("EditForm.aspx?Index:"+ index +""); 
        } 
    } 

Thanks
Princy.
0
Alec
Top achievements
Rank 1
answered on 19 May 2009, 07:04 AM
Okay...but i cant use index, it will have to be the id of the record...
0
Princy
Top achievements
Rank 2
answered on 19 May 2009, 07:55 AM
Hello Alec,

You can either try accessing the id field using the datakeyvalue for the mastertableview as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"  OnItemCommand="RadGrid1_ItemCommand"
    <MasterTableView  DataSourceID="SqlDataSource1" DataKeyNames="Id"

c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)     
    {     
        if (e.CommandName == "RowClick" && e.Item is GridDataItem)     
        {     
            GridDataItem dataItem = (GridDataItem)e.Item;     
            string strtxt = dataItem.GetDataKeyValue("Id").ToString();     
            Response.Redirect("EditForm.aspx?Index:"+ strtxt +"");     
        }     
    }    

or you can access the id directly if the field is set as a column in the grid:
c#:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)   
    {   
        if (e.CommandName == "RowClick" && e.Item is GridDataItem)   
        {   
            GridDataItem dataItem = (GridDataItem)e.Item;   
            string strtxt = dataItem["Id"].Text;   
            Response.Redirect("EditForm.aspx?Index:"+ strtxt +"");   
        }   
    }   

Thanks
Princy.
0
Alec
Top achievements
Rank 1
answered on 20 May 2009, 02:50 AM
Princey, that gave me a null dataItem 

I have datakeyname in mastertableview. Is it because i bind the grid at code behind?

rgLead.DataSource =

LeadBO.getAllLeads();
rgLead.DataBind();

 

 

 

 

 

 

 

 

Tags
Grid
Asked by
Alec
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Alec
Top achievements
Rank 1
Share this question
or