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

Access radnumerictextboxes inside radgrid on clientside while add new record

6 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Najah
Top achievements
Rank 1
Najah asked on 22 Dec 2009, 09:29 AM
Dear Telerik team,

My support has just expired. While my office renews it, I have a question. I want to access radnumerictextboxes which are inside RadGrid while adding a new record on client side. I want to multiply values of two radnumerictextboxes and display the result in third.

 

 

function SetTotalCost2(sender, args)  
{   
var grid = $find('<%=gridBudget.ClientID %>');    
var MasterTable = grid.get_masterTableView();    
var Rows = MasterTable.get_dataItems();  
 
var textbox1 = Rows[1].findControl("txtCostPerUnit"); //which row no. to use to get add new row reference  
var textbox2 = Rows[1].findControl("txtNoOfUnit");   
var textbox3 = Rows[1].findControl("txtTotalCost");   
textbox3.set_value(textbox1.get_value() * textbox2.get_value());  


Could you please help. I don't know how to access row while adding a new record on client side.

Many thanks,
Sana Khurram

 

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 22 Dec 2009, 11:01 AM
Hi Sunny,

Here is the code that I tried to achieve same scenario. I hope this would help you.

ASPX:
 
<telerik:GridTemplateColumn> 
        <EditItemTemplate> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server"
            </telerik:RadNumericTextBox> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn> 
        <EditItemTemplate> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox2" runat="server"
            </telerik:RadNumericTextBox> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn> 
        <EditItemTemplate> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox3" runat="server"
            </telerik:RadNumericTextBox> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 

CS:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem  && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;  
            RadNumericTextBox textbox1 = item.FindControl("RadNumericTextBox1"as RadNumericTextBox;       // Get the textbox for column Price    
            RadNumericTextBox textbox2 = item.FindControl("RadNumericTextBox2"as RadNumericTextBox;    // Get the textbox for column Quantity      
            RadNumericTextBox textbox3 = item.FindControl("RadNumericTextBox3"as RadNumericTextBox; // Get the textbox for column "Total", if it is template as shown in aspx     
 
            textbox1.Attributes.Add("onFocusout""return show('" + textbox1.ClientID + "','" + textbox2.ClientID + "','" + textbox3.ClientID + "')"); 
            textbox2.Attributes.Add("onFocusout""return show('" + textbox1.ClientID + "','" + textbox2.ClientID + "','" + textbox3.ClientID + "')"); 
            textbox3.Attributes.Add("onfocus""return show('" + textbox1.ClientID + "','" + textbox2.ClientID + "','" + textbox3.ClientID + "')");   
        } 
    } 

JavaScript:
 
<script type="text/javascript">  
function show(cntl1, cntl2, cntl3)    
{   
    var text1 = $find(cntl1);   
    var text2 =  $find(cntl2);   
    var text3 =  $find(cntl3); 
    var total = text1.get_value() * text2.get_value();   
    text3.set_value(total);   
</script>  

Regards,
Shinu.
0
Najah
Top achievements
Rank 1
answered on 22 Dec 2009, 11:06 PM
Thanks you **so much**, it solved my problem right away...
East or west, telerik support team is the best !

I have another small question. I have a radcombobox on the same grid and I want its value to be multiplied by the values of two text boxes too. I wrote onchange, onblur, onfocus events. None of them worked. onfocusout worked but only when the focus is out of the radcombobox. Could you please explain why onchange is not working or is there any other event that i can use here ?

Many thanks,
Sana Khurram
0
Shinu
Top achievements
Rank 1
answered on 23 Dec 2009, 01:00 PM
Hello Sunny,

You could attach the combobbox client event "OnClientSelectedIndexChanged" as shown below from code behind.
    RadComboBox1.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged";

Also access the textbox from code and save the ClientID in a HiddenField. Then in the client side event handler (OnClientSelectedIndexChanged), access the textbox using the ClientID saved in HiddenField and calculate and set the value accordingly.

-Shinu.
0
Najah
Top achievements
Rank 1
answered on 23 Dec 2009, 02:35 PM
Thank you for your reply.

I forgot to mention earlier. I want the values to be multiplied not only on add new record but on edit a row too. I have written following code and then the same code that you wrote earlier but it gives 'object reference not set to an instance of an object' error.

if (e.Item is GridEditableItem)  
GridEditableItem item = (GridEditableItem)e.Item; 

Is there any mistake here?

Regards,
Sana Khurram
0
Najah
Top achievements
Rank 1
answered on 24 Dec 2009, 11:40 AM
I found a solution myself.

Thanks anyway !
0
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Sep 2011, 01:11 PM
Sorry by mistake
Tags
Grid
Asked by
Najah
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Najah
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or