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

RadNumericTextBox in dynamicaly generated control

2 Answers 77 Views
Input
This is a migrated thread and some comments may be shown as answers.
Zdeněk
Top achievements
Rank 1
Zdeněk asked on 09 Dec 2010, 07:43 PM
Hi all,
could please somebody help me with this problem?
I have RadNumericTextBox in GridTemplateColumn of RadGrid. I want two things:
- OnKeyPress it will compute differnce between its value and some start value
- OnValueChanged it will update value in database (through AJAX call)

ASPX page snippet:
<telerik:GridTemplateColumn UniqueName="colValue" HeaderText="Stav" ItemStyle-Width="35px">
    <ItemTemplate>
    <telerik:RadNumericTextBox
        ID="txtCounterValue" runat="server"  Width="80"
        MinValue="0" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0"
        EnabledStyle-HorizontalAlign="Right" EnabledStyle-Font-Bold="true"
        >
        <ClientEvents  OnKeyPress="CounterKeyPress"OnValueChanged="CounterValueChanged"  />
    </telerik:RadNumericTextBox>
  <div id="txtStartValue" runat="server" ></div>
    <div id="txtDifference" runat="server" ></div>
                                         
 
    </ItemTemplate>
</telerik:GridTemplateColumn>

Snippet of code-behind:
Protected Sub rgDeviceCountersDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
            Dim myCounter = DirectCast(e.Item.DataItem, Data.DeviceCounter)
            Dim txtCounterValue As RadNumericTextBox = DirectCast(e.Item.FindControl("txtCounterValue"), RadNumericTextBox)
txtCounterValue =myCounter.StartValue
            Dim txtStartValue As HtmlGenericControl = DirectCast(e.Item.FindControl("txtStartValue"), HtmlGenericControl)
txtDtartValue.InnerText=myCounter.StartValue
            Dim txtDifference As HtmlGenericControl = DirectCast(e.Item.FindControl("txtDifference"), HtmlGenericControl)
        End Sub

Snippet of javascript:
var ajaxManager;
 
function pageLoad() {
ajaxManager = $find("<%=RadAjaxManager.GetCurrent(Page).ClientID %>");
            }

function CounterKeyPress(sender, eventArgs) {
                /* update InnerText of txtDifference with difference between RadNumericTextBox andtxtStartValue */
/* HOW TO ACHIEVE THIS? :-) */
            }

function
CounterValueChanged(sender, eventArgs) {
                /* Count difference betweentxtStartValue and txtCounterValue and call AJAX update of record (how to get Primary Id from ClientDataKeyNames?) */
ajaxManager.ajaxRequest(... AND WHAT HERE ...?);
            }





Thank you very much for your help!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Dec 2010, 02:58 PM
Hello Zdenek Plachy ,

Try the following approach .
 In 'OnKeyPress' event of RadNumericTextBox invoke the ajaxRequest and pass the row index to server side. In AjaxManager_AjaxRequest server event, you can access the corresponding cell value and perform the calculation. You can do the same using 'OnValueChanged' event and perform updation on server side.

The following forum shows how to fing the row index from client side.
Get grid's row index of valueChanged radTextBox

And check out the following documentation for accessing cells and rows in RadGrid.
Accessing cells and rows
 
-Shinu.
0
Zdeněk
Top achievements
Rank 1
answered on 10 Dec 2010, 05:23 PM
Thank you very much!
Meanwhile I made it completely client side. For database update I wrote my own XMLHttpRequest, calling other aspx page, where database logic make the rest.

Next time I will wrestle with AJAX your (and correct) way :-)
Tags
Input
Asked by
Zdeněk
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Zdeněk
Top achievements
Rank 1
Share this question
or