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

Pass column data from radgrid on Client Event RowClick

8 Answers 275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 1
Danny asked on 11 Aug 2009, 09:18 PM
I am looking to pass data from the rows of a datagrid into javascript arguments using on the Client Event RowClick.

For example. I am returning a list of names, and addresses into a grid. I want to display these names and addresses in a javascript message box. e.g. Alert ("Name:" + arg1 + "  Address: " + Arg2)

If this is not possible. i would like to open a new RadWindow and specify the query string directly from RowClick client event.

Any help would be much appreciated.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 12 Aug 2009, 05:40 AM
Hi Danny,

Try the following client side approach and see whether it meets your requirement.

ASPX:
 
 <ClientEvents  OnRowClick="RowClickEvent"  /> 

JS:
 
<script type="text/javascript" > 
 function RowClickEvent(sender, eventArgs) 
 { 
   var MasterTable = sender.get_masterTableView(); 
   var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
   var Name = MasterTable.getCellByColumnUniqueName(row, "ProductName").innerHTML ; 
   var ID = MasterTable.getCellByColumnUniqueName(row, "ProductID").innerHTML ; 
   alert("ProductName: "+ Name + ", ID:" +ID) 
 } 
</script> 

Thanks
Princy

0
illumination
Top achievements
Rank 2
answered on 04 Sep 2009, 03:49 PM
How about if I try to do the same thing but passing the row data from grid into textboxes when the row is clicked?
0
Princy
Top achievements
Rank 1
answered on 07 Sep 2009, 05:34 AM
Hi,

I hope the TextBox is inside the ItemTemplate of a GridTemplateColumn and you are trying to pass the row value to the textbox on clicking the Grid row. If so try the following code snippet and see whether it helps.

ASPX:
 
     <telerik:GridTemplateColumn HeaderText="TempCol" > 
               <ItemTemplate> 
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
                </ItemTemplate> 
           </telerik:GridTemplateColumn> 

JS:
 
 
<script type="text/javascript" > 
 function RowClick(sender, eventArgs) 
 { 
   var MasterTable = sender.get_masterTableView(); 
   var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
   var Name = MasterTable.getCellByColumnUniqueName(row, "ProductName").innerHTML ; 
   var ID = MasterTable.getCellByColumnUniqueName(row, "ProductID").innerHTML ; 
 
 // access the textbox here 
   var txtbx =row.findElement("TextBox1"); 
   txtbx.value="ProductName: "+ Name + ", ID:" +ID; 
 } 
</script> 


Regards
Princy
0
illumination
Top achievements
Rank 2
answered on 08 Sep 2009, 12:11 PM
The textboxes are not inside the RadGrid. They are all standalone textboxes. How will I pass the value from the grid onto them? Thank you :)  or can I also get a session value from the radgrid when the row is clicked?
0
illumination
Top achievements
Rank 2
answered on 09 Sep 2009, 02:53 PM
Got it to work on passing the datagrid cell values to textboxes on RowClick by putting the radgridsteps_onselectedindexchanged:

 

Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)

 

Dim strID as string = dataItem("UniqueName").Text

But I'm having trouble to where I should put this value on the page load so it will load even before the user select any row. I have a master and a detail grid.

Then I have another problem:


Protected Sub RadGridSteps_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridSteps.ItemDataBound  
If Not IsPostBack Then  
If TypeOf e.Item Is GridDataItem Then  
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
Dim strID As String = dataItem("STEPID").Text  
lblSTEPID.Text = strID 
Session("STEPID") = strID  
End If  
End If  
End Sub  
It seems by using the itemdatabound when the radgrid first load, it will load the first row but then when I click on the expandcolapsecolumn then the child table will grab the last Session("StepID") on all the children table. any idea where I can look for this solution? Please point me to the right way. Thank you!


0
Yavor
Telerik team
answered on 14 Sep 2009, 06:10 AM
Hello,

To see more information along the lines of the functionality which was originally requested, please refer to the following article:

http://www.telerik.com/community/code-library/aspnet-ajax/general/using-radconfirm-with-grid-hierarchy.aspx

I hope it gets you started properly.

Best wishes,
Yavor
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
bradley baker
Top achievements
Rank 1
answered on 17 Nov 2009, 05:15 PM
How would you pass the value in a templated grid?  the colum is search able but whenever I try to run it there is no index value.
0
Yavor
Telerik team
answered on 20 Nov 2009, 11:01 AM
Hi bradley,

Tha value is preset from the code-behind, as shown in the following code snippet:

if ((item is GridDataItem && (item.OwnerTableView.DataKeyNames[0] == "OrderID")))  
                    {  
                        string orderID;  
                        GridDataItem dataItem = (GridDataItem)item;  
                        orderID = dataItem["OrderID"].Text;  
                        Image image = (Image)dataItem["TemplateColumn"].FindControl("Image1");  
                        image.Attributes.Add("onclick", "rConfirm('" + orderID + "');");  
                    }  


The following article further elaborates on how to access different cell elements:

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

I hope this information helps.

Greetings,
Yavor
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.
Tags
Grid
Asked by
Danny
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
illumination
Top achievements
Rank 2
Yavor
Telerik team
bradley baker
Top achievements
Rank 1
Share this question
or