Hi,
I am using RadGrid which has 4 columns. column2 = GridTemplateColumn with ItemTemplate as textbox and column4 = GridTemplateColumn with ItemTemplate as checkbox.
I need to get the value of the textbox and do some calculation and assign the calculated value to column3 for that row.
I am trying to do it on client side and this is my .ascx code for onblur of the textbox :
In the above code, the value of 'cell' is always coming as null.
file.ascx.cs
Please help me understand what is going wrong in the code.
Thanks,
Preeti
I am using RadGrid which has 4 columns. column2 = GridTemplateColumn with ItemTemplate as textbox and column4 = GridTemplateColumn with ItemTemplate as checkbox.
I need to get the value of the textbox and do some calculation and assign the calculated value to column3 for that row.
I am trying to do it on client side and this is my .ascx code for onblur of the textbox :
function
ConvertToUSD(index) {
var
grid = $find(
"<%=AntiXss.JavaScriptEncode(rgdPOTypes.ClientID).Trim('\'')%>"
);
var
MasterTable = grid.get_masterTableView();
var
Row = MasterTable.get_dataItems()[index];
var
cell = MasterTable.getCellByColumnUniqueName(Row,
"TextboxCurreny"
);
if
(!cell) {
var
nextcell = MasterTable.getCellByColumnUniqueName(Row,
"InUSD"
);
nextcell .InnerHTML = cell.InnerHTML * 50;
}
}
In the above code, the value of 'cell' is always coming as null.
file.ascx.cs
protected
void
rgdPOTypes_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TextBox txtBox = (TextBox)item.FindControl(
"TextboxCurreny"
);
txtBox.Attributes.Add(
"onblur"
,
"ConvertToUSD('"
+ item.ItemIndex +
"')"
);
}
}
Please help me understand what is going wrong in the code.
Thanks,
Preeti
6 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 18 Sep 2013, 10:26 AM
Hi Preeti,
Please try the below code snippet .
ASPX:
C#:
JS:
Thanks,
Princy
Please try the below code snippet .
ASPX:
<
telerik:GridTemplateColumn
DataField
=
"EmployeeID"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
Text='<%# Eval("EmployeeID")%>'></
asp:TextBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShipVia"
HeaderText
=
"ShipVia"
UniqueName
=
"ShipVia"
/>
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TextBox txtBox = (TextBox)item.FindControl(
"TextBox1"
);
txtBox.Attributes.Add(
"onblur"
,
"ConvertToUSD('"
+ item.ItemIndex +
"')"
);
}
}
JS:
<script type=
"text/javascript"
>
function
ConvertToUSD(index) {
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
MasterTable = grid.get_masterTableView();
var
Row = MasterTable.get_dataItems()[index];
var
cell = Row.findElement(
"TextBox1"
);
//Access the Template TextBox
var
value = cell.value;
var
nextcell = MasterTable.getCellByColumnUniqueName(Row,
"ShipVia"
);
//Access the bound column
nextcell.innerText = value * 50;
//Set text for the Bound Column
}
</script>
Thanks,
Princy
0

Preeti
Top achievements
Rank 1
answered on 19 Sep 2013, 02:36 PM
Thanks Princy.
But I am getting error for
findElement does not exist. :(
FYI, I have changed the textbox to RadNumericTextbox. and accordingly changed the code in .cs file while adding attribute (casting with RadNumericTextbox).
Can this be causing the problem?
Please suggest.
Thanks.
But I am getting error for
var
cell = Row.findElement(
"TextBox1"
);
findElement does not exist. :(
FYI, I have changed the textbox to RadNumericTextbox. and accordingly changed the code in .cs file while adding attribute (casting with RadNumericTextbox).
Can this be causing the problem?
Please suggest.
Thanks.
0

Princy
Top achievements
Rank 2
answered on 20 Sep 2013, 03:39 AM
Hi Preeti,
The error you are facing is caused when you have changed the textbox to RadNumericTextbox.Please modify the code as shown below.I have marked places that are edited in JS.
ASPX:
C#:
JS:
Thanks,
Princy
The error you are facing is caused when you have changed the textbox to RadNumericTextbox.Please modify the code as shown below.I have marked places that are edited in JS.
ASPX:
<
telerik:RadNumericTextBox
ID
=
"RadNumTextBox1"
runat
=
"server"
Text='<%# Eval("EmployeeID")%>'></
telerik:RadNumericTextBox
>
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
RadNumericTextBox txtBox = (RadNumericTextBox)item.FindControl(
"RadNumTextBox1"
);
txtBox.Attributes.Add(
"onblur"
,
"ConvertToUSD('"
+ item.ItemIndex +
"')"
);
}
}
JS:
<script type=
"text/javascript"
>
function
ConvertToUSD(index) {
var
grid = $find(
"<%=RadGrid1.ClientID %>"
);
var
MasterTable = grid.get_masterTableView();
var
Row = MasterTable.get_dataItems()[index];
var
cell = Row.findControl(
"RadNumTextBox1"
);
//Edited
var
value = cell._value;
//Edited
var
nextcell = MasterTable.getCellByColumnUniqueName(Row,
"ShipVia"
);
nextcell.innerText = value * 50;
}
</script>
Thanks,
Princy
0

Preeti
Top achievements
Rank 1
answered on 20 Sep 2013, 05:10 AM
Hi Princy,
Thanks a lot for that edited code. There is a minor change though. The value should be accessed as below.
But unfortunately I am still getting null for nextcell. Why is the 'getCellByColumnUniqueName returning null? Is the parameter being passed incorrectly ? Another piece of info: I am doing this in the .ascx file. Hope that is not an issue.
I am attaching below the grid properties also:
Thanks
Thanks a lot for that edited code. There is a minor change though. The value should be accessed as below.
But unfortunately I am still getting null for nextcell. Why is the 'getCellByColumnUniqueName returning null? Is the parameter being passed incorrectly ? Another piece of info: I am doing this in the .ascx file. Hope that is not an issue.
function
ConvertToUSD(index) {
var
grid = $find(
"<%=AntiXss.JavaScriptEncode(rgdGrid.ClientID).Trim('\'') %>"
);
var
MasterTable = grid.get_masterTableView();
var
Row = MasterTable.get_dataItems()[index];
var
cell = Row.findControl(
"txtRadNum"
);
var
value = cell._element.value;
//Edited
var
nextcell = MasterTable.getCellByColumnUniqueName(Row,
"InUSD"
);
//Access the bound column
nextcell.innerText = str;
//Set text for the Bound Column
alert(nextcell.innerText);
}
I am attaching below the grid properties also:
<telerik:RadGrid ID=
"rgdGrid"
runat=
"server"
AllowPaging=
"True"
AllowSorting=
"True"
AutoGenerateColumns=
"False"
enableajax=
"False"
Skin=
"WebBlue"
skinspath=
"~/Skins/RadGrid"
OnNeedDataSource=
"rgdGrid_NeedDataSource"
OnItemCreated=
"rgdGrid_ItemCreated"
OnItemDataBound=
"rgdGrid_ItemDataBound"
OnPageSizeChanged=
"rgdGrid_PageSizeChanged"
AllowMultiRowSelection=
"true"
>
<MasterTableView DataKeyNames=
"SubClass,ApprovalLimit,InUSD,IsManaged"
ShowHeadersWhenNoRecords=
"true"
TableLayout=
"Fixed"
CssClass=
"wrapword"
Width=
"100%"
>
<PagerStyle Mode=
"NextPrevNumericAndAdvanced"
AlwaysVisible=
"true"
/>
<HeaderStyle Width=
"20px"
Font-Bold=
"true"
HorizontalAlign=
"Left"
/>
<ItemStyle HorizontalAlign=
"Left"
/>
<RowIndicatorColumn Visible=
"False"
>
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable=
"False"
Visible=
"False"
>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField=
"SubClass"
HeaderText=
"SubClass"
SortExpression=
"SubClass"
UniqueName=
"SubClass"
ItemStyle-Width=
"25%"
ItemStyle-Wrap=
"true"
>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField=
"ApprovalLimit"
AllowFiltering=
"False"
ItemStyle-Wrap=
"true"
HeaderText=
"Approval Limit"
UniqueName=
"ApprovalLimit"
ItemStyle-Width=
"20%"
>
<ItemTemplate>
<telerik:RadNumericTextBox ID=
"txtRadNum"
AutoPostBack=
"true"
runat=
"server"
Skin=
"Office2007"
OnTextChanged=
"txtRadNum_TextChanged"
Columns=
"20"
MinValue=
"0"
onkeyup=
"javascript:RemoveInvalidChars(this);"
Text=
'<%# (AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, "ApprovalLimit").ToString())) %>'
/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField=
"InUSD"
ReadOnly=
"true"
HeaderText=
"In USD"
UniqueName=
"InUSD"
ItemStyle-Width=
"15%"
ItemStyle-Wrap=
"true"
HeaderStyle-HorizontalAlign=
"left"
>
<HeaderStyle HorizontalAlign=
"Left"
></HeaderStyle>
<ItemStyle Wrap=
"True"
Width=
"25%"
></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField=
"IsManaged"
AllowFiltering=
"False"
UniqueName=
"IsManaged"
HeaderText=
"Is Managed"
>
<HeaderStyle Width=
"20px"
HorizontalAlign=
"Left"
/>
<ItemStyle Width=
"20%"
/>
<ItemTemplate>
<asp:CheckBox ID=
"chkManaged"
runat=
"server"
Enabled= '<%
# ((AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, "ReqClassSubClass").ToString()).Contains("GEN")) ||
(AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem,
"ReqClassSubClass"
).ToString()).Contains(
"CONT"
)) ||
(AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem,
"ReqClassSubClass"
).ToString()).Contains(
"STDMKT"
))) %>'
Checked=
'<%# (AntiXss.HtmlEncode(DataBinder.Eval(Container.DataItem, "IsManaged").ToString())).ToLower() == "true"? true:false%>'
/>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Resizing AllowColumnResize=
"false"
AllowRowResize=
"false"
ClipCellContentOnResize=
"true"
/>
</ClientSettings>
<FilterMenu Skin=
"WebBlue"
EnableTheming=
"True"
>
<CollapseAnimation Type=
"OutQuint"
Duration=
"200"
></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
Thanks
0

Preeti
Top achievements
Rank 1
answered on 20 Sep 2013, 08:33 AM
Got it!
I was setting the GridBounDColumn visible false and that is why getting null. :)
Thanks!!
I was setting the GridBounDColumn visible false and that is why getting null. :)
Thanks!!
0
Hi Preeti,
See the forum post below for more information on this matter:
http://www.telerik.com/community/forums/aspnet-ajax/grid/breaking-change-hidden-column-cell-text-is-not-persisted-in-viewstate.aspx
Regards,
Maria Ilieva
Telerik
See the forum post below for more information on this matter:
http://www.telerik.com/community/forums/aspnet-ajax/grid/breaking-change-hidden-column-cell-text-is-not-persisted-in-viewstate.aspx
Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.