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

get numerictextbox value based on rowindex

3 Answers 238 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Loyal User
Top achievements
Rank 1
Loyal User asked on 18 Dec 2013, 08:45 AM
hello all ,

I have a radgrid that contains a Template column with radnumericTextBox ,
Users will fill these numericTextBox, every textbox should have a value less than previous one ,

<telerik:GridTemplateColumn HeaderText="value" UniqueName="value">
<ItemTemplate>            
 
<telerik:RadNumericTextBox runat="server" ID="value" NumberFormat-AllowRounding="false" >
     <NumberFormat GroupSeparator=""/>
    <ClientEvents OnValueChanged="checkValues" />  
    </telerik:RadNumericTextBox>
</ItemTemplate>           
 
</telerik:GridTemplateColumn>

if user add 20 in first row ,
second row should contains 20 or less ...

in "checkValues" function , i want to read value of previous row to compare with current value ..
how can i get it based on row index ?



How can i achieve this task ?

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 18 Dec 2013, 10:31 AM
Hi,

Please have a look into the following code snippet which works fine at my end.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
    AllowPaging="true" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            <telerik:GridTemplateColumn HeaderText="value" UniqueName="value">
                <ItemTemplate>
                    <telerik:RadNumericTextBox runat="server" ID="value" NumberFormat-AllowRounding="false">
                        <NumberFormat GroupSeparator="" />
                        <ClientEvents OnValueChanged="checkValues" />
                    </telerik:RadNumericTextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        RadNumericTextBox Editbtn = item.FindControl("value") as RadNumericTextBox;
        Editbtn.Attributes.Add("rowindex", item.ItemIndex.ToString());
    }
}

JavaScript:
<script type="text/javascript">
    function checkValues(sender, args) {
        var radGrid = $find('<%=RadGrid1.ClientID %>');
        var masterTable = radGrid.get_masterTableView();
        var row = sender._element.getAttribute("rowindex");
        if (row != 0) {
            for (var i = 0; i < row; i++) {
                if (masterTable.get_dataItems()[i].findControl("value").get_value() < args.get_newValue()) {
                    sender.set_value(" ");
                    sender.focus();
                }
            }
        }
    }
</script>

Thanks,
Shinu.
0
Loyal User
Top achievements
Rank 1
answered on 18 Dec 2013, 11:02 AM
thanks a lot Shinu ,
that's exactly what i was looking for  ..

but i still have a question :
when user add a value , the algorithm (for loop) compare new value with all previous values,
no problem with results ,
but , Is there  another way to prevent looping all grid in each check validation ??
only compare it with previous ...
0
Loyal User
Top achievements
Rank 1
answered on 18 Dec 2013, 11:35 AM
to avoid looping, i have delete "for loop" and compare value with previous (row-1) :

if (masterTable.get_dataItems()[row-1].findControl("commissionTxt").get_value() < args.get_newValue()) ...


thanks a lot ..
Tags
Grid
Asked by
Loyal User
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Loyal User
Top achievements
Rank 1
Share this question
or