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

Get gridbouncolumn Text in javascript

5 Answers 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sudha Gajendran
Top achievements
Rank 1
Sudha Gajendran asked on 23 Mar 2010, 02:33 PM
I have a RadGrid with GridBoundColumns . I need to do javascript validations for the BoundColumns.

I tried the following code .But I was getting error in MasterTableView

function

 

Validation(txt)

 

{

var grid=document.getElementById("<%= Radgrid1.ClientID %>");
var masterTable = grid.get_masterTableView();  
        for (var i = 0; i < masterTable.get_dataItems().length; i++)  
        {  
            // to access the textbox in each row 
           var txtbx = masterTable.get_dataItems()[i].findElement("vchConsignmentTypeName");
 alert(txtbx);
             // set alert
 
        }  
}

<

 

telerik:GridBoundColumn DataField="vchConsignmentTypeName"  HeaderText="Consignment*" UniqueName="vchConsignmentTypeName" />

 


I am calling the javascript from code behind as

Protected

 

Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand

 

ScriptManager.RegisterStartupScript(

Me, Me.GetType(), "Msg", "<script>Validation();</script>", False)

 

End

 

Sub

I am getting the error exactly at grid.get_masterTableView();  
Please help me

 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Mar 2010, 03:18 PM
Hello Sudha,

A better idea is attaching the 'OnCommand' event and check for the CommandName is "Update", and if yes invoke the validation function rather than calling from code behind. Here is the example of how to access the cell values from each row when clicking the update button.

JavaScript:
 
<script type="text/javascript"
    function OnCommand(sender, args) { 
        if (args.get_commandName() == "Update") { 
    
            var grid = sender; 
            var masterTable = grid.get_masterTableView(); 
            for (var i = 0; i < masterTable.get_dataItems().length; i++) { 
                var row = masterTable.get_dataItems()[i]; 
                var cell = masterTable.getCellByColumnUniqueName(row, "CustomerID"); 
                alert(cell.innerHTML); 
            } 
        } 
    } 
</script> 

Regards,
Princy.
0
Sudha Gajendran
Top achievements
Rank 1
answered on 24 Mar 2010, 07:38 AM
Thanks for your reply.

I again find a problem with alert(cell.innerHTML); 

cell.innerHTML retrieves the cell values of all the rows but for the row that has been given updatecommand it shows as
<INPUT style="....." value=a ../>
i am not able to extract the particular value of the cell that is updated.
Please help me .

0
Yavor
Telerik team
answered on 29 Mar 2010, 07:49 AM
Hello Sudha,

In order to get a reference to the edit form fields, you can use the client ids of the element(s).
You can get the client ids, by accessing the field(s) of the edit form on the server, as shown in the following topic:

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

These can be stored in hidden inputs on the page, to be accessed at a later stage, for example on the client.

All the best,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sudha Gajendran
Top achievements
Rank 1
answered on 29 Mar 2010, 09:48 AM
Thanks for the reply.

But i want to get the cell values in javascript instead of code behind.
cell.innerHTML gets the values of particular column except for the row that is going to be updated.

Please help me .
0
Yavor
Telerik team
answered on 01 Apr 2010, 07:46 AM
Hi Sudha,

Indeed, once you store the client id in a hidden input on the page, you will be able to access the client id from the client, at any time. Once you have the id, you can locate the controls which are rendered as part of the edit form.
Let me know if I am leaving something out.

All the best,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Sudha Gajendran
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sudha Gajendran
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or