6 Answers, 1 is accepted
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:
c#:
Thanks
Princy.
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.
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#:
Thanks
Princy.
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:
c#:
or you can access the id directly if the field is set as a column in the grid:
c#:
Thanks
Princy.
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?
I have datakeyname in mastertableview. Is it because i bind the grid at code behind?
rgLead.DataSource =
LeadBO.getAllLeads();
rgLead.DataBind();