I've tried several options to retrieve a label and or textboxes via javascript on my grid in the OnClientClose (which retrieves values I want to insert into a (checkbox) selected row.
I get as far as getting into the "iterating thru the dataitems " ,(loops thru 16 rows correctly)
BUT, getting the column or/and the labels by their unique id is a problem.
I am using Telerik RaControls v2009.2
The column markup is
<telerik:GridTemplateColumn UniqueName ="ORateCBX" >
<ItemTemplate>
<asp:CheckBox ID="cbxORate"
runat="server" Width="100%" height = "18px" AutoPostBack="true"
OnCheckedChanged="cbxORate_CheckedChanged"/>
<asp:Label id="lblORate_Id" "
runat="server Visible="false" Width="5px" height = "18px"></asp:Label>
<asp:TextBox id="txtORate"
runat="server" Visible="false" Width="5px" height = "18px"></asp:TextBox>
<asp:TextBox id="txtReason"
runat="server" Visible="false" Width="5px" height = "18px"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
The javascript (in onClientClose)
var arg = args.get_argument();
if (arg)
{
var RatePerc = arg.RatePerc;
var seldate = arg.Reason;
var masterTableView;
var length;
var grid = $find("<%
= grvCoverelements.ClientID %>");
if (grid)
{
masterTableView = grid.get_masterTableView();
}
if (masterTableView)
{
var firstDataItems = masterTableView.get_dataItems();
if (firstDataItems)
{
length = firstDataItems.length;
// alert("length = " + length);
}
for (var i = 0; i < length; i++)
{
alert(i ); //Successful
var dataItem = firstDataItems[i].get_element("ORateCBX");
if (dataItem)
{
//unsuccessful condition everytime...i.e. not getting the GridTemplateColumn UniqueName ="ORateCBX"
alert("dataItem is " + dataItem);
// 1. Is it the correct row (the one the user clicked on to insert (via popup) the new values from args.
if (checkBox && checkBox.checked )
{
// 1. Get the rate textbox
var txtRate = dataItem.findElement("txtORate");
//2. Is it the correct row and checkbox
if ( txtRate.value =" " )
{
//3. Insert the new value from Arg.RatePerc
txtRate.value = Arg.RatePerc;
//4 Insert the new value from Arg.Reason
var txtReason = dataItem.findElement("txtReason");
txtReason.value = Arg.Reason;
}
}
}
}
__doPostBack(
"NewOrate", arg);
}
In other words it never finds the Column (GridTemplate col with the unique name of "ORateCBX" ???
I have tried this approach as well, but it does not even iterate thru the grids rows!
// for (var i=0; i < masterTableView.Rows.length; i++)
// {
// alert("looping" ); //...............//NOT successful
// var cell = masterTableView.GetCellByColumnUniqueName(masterTableView.Rows[i] , "ORateCBX");
// if (cell) {alert("Cell")};
// var dataItem = dataitems[i].findElement("txtORate")[0];
// if (checkBox && checkBox.checked)
// {
// Find the textboxes "txtRate and TxtReason and populate them from args
/// }
// }
Thanks
Neal