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

how to get rowindex of the cell that trigger this clientside function

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Weilun
Top achievements
Rank 1
Weilun asked on 18 Jan 2012, 09:27 AM

Is there anyway to get rowindex of the cell that trigger this function.
I know there is a way which uses OnRowClick or OnRowSelect.
In my case i dont want the user to selectrow to update the cell.

This there anyway to change the 4 into rowindex

function editQuantity(sender, eventArgs) {
    var masterTable = $find("<%= CartRadGrid.ClientID %>").get_masterTableView();
        masterTable.updateItem(4);
}


This is my radgrid

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="CartRadGrid">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="CartRadGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" Skin="Default">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="CartRadGrid" runat="server" AllowSorting="True" ShowStatusBar="True"
CellSpacing="0" DataSourceID="CartObjectDataSource" GridLines="None" ShowFooter="True"
Skin="Hay" AllowAutomaticDeletes="True" AutoGenerateColumns="False"
onitemcommand="CartRadGrid_ItemCommand" AllowAutomaticUpdates="True">
<ClientSettings ClientEvents-OnRowClick="OnRowClick">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowClick="OnRowClick"></ClientEvents>
</ClientSettings>
<MasterTableView DataSourceID="CartObjectDataSource" DataKeyNames="productID" EditMode="InPlace" CommandItemDisplay="Top">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<Columns>
<telerik:GridBinaryImageColumn DataField="image" ImageHeight="80px" ImageWidth="80px"
UniqueName="image" ResizeMode="Fit" HeaderText="Item">
<HeaderStyle Width="10%" HorizontalAlign="Center" />
</telerik:GridBinaryImageColumn>
<telerik:GridBoundColumn DataField="productID"
FilterControlAltText="Filter column column" HeaderText="id"
UniqueName="productID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="productName"
FilterControlAltText="Filter productName column" HeaderText="Name"
UniqueName="productName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="productDesc"
FilterControlAltText="Filter productDesc column" HeaderText="Description"
UniqueName="productDesc">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="price" DataFormatString="{0:C}"
FilterControlAltText="Filter price column" UniqueName="price"
HeaderText="Unit price">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="quantity"
FilterControlAltText="Filter TemplateColumn column" UniqueName="quantity"
HeaderText="Quantity" SortExpression="quantity">
<ItemTemplate>
<telerik:RadNumericTextBox ID="quantityTextBox" runat="server"
ShowSpinButtons="True" width="50px"
DbValue='<%# Convert.ToDouble(Eval("quantity")) %>'
DataType="System.Int32" Culture="en-SG" NumberFormat-DecimalDigits="0" MinValue="0" MaxValue="999"
ClientEvents-OnValueChanged="editQuantity">
</telerik:RadNumericTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="stock"
FilterControlAltText="Filter stock column" HeaderText="Stock left"
UniqueName="stock">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="total" DataFormatString="{0:C}"
FilterControlAltText="Filter total column" HeaderText="Total"
UniqueName="total" Aggregate="Sum" FooterAggregateFormatString="Total: {0:C}" FooterStyle-CssClass="total">
<FooterStyle CssClass="total"></FooterStyle>
</telerik:GridBoundColumn>
<telerik:GridButtonColumn Text="Delete" CommandName="Delete"
ButtonType="ImageButton" UniqueName="Delete" CommandArgument="asd"
FilterControlAltText="Filter Delete column">
<HeaderStyle Width="2%" />
</telerik:GridButtonColumn>
</Columns>
<PagerStyle AlwaysVisible="True" />
<FooterStyle Height="30px" />
<CommandItemTemplate>
<table border="0" style="width: 100%;" class="rgCommandTable">
<tr>
<td align="left"><asp:Label ID="Label1" runat="server" Text="My Cart"></asp:Label></td>
<td align="right">
<asp:Button CommandName="RebindGrid" runat="server" ID="btnRefresh" Text="Refresh" title="Refresh" CssClass="rgRefresh" />
<asp:Label ID="refreshLabel" runat="server" Text="Refresh"></asp:Label>
</td></tr>
</table>
</CommandItemTemplate>
</MasterTableView>
<FilterMenu EnableImageSprites="False"></FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
</telerik:RadGrid>
<asp:ObjectDataSource ID="CartObjectDataSource" runat="server"
SelectMethod="loadCart" TypeName="GroceryStore.Cart.Cart">
</asp:ObjectDataSource>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2012, 10:22 AM
Hello,

One suggestion is you can access the RadNumericTextBox from server side and pass the index as shown below.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   RadNumericTextBox txt = (RadNumericTextBox)item.FindControl("RadNumericTextBox1");
   int index = e.Item.ItemIndex;
   txt.ClientEvents.OnValueChanged= "function (sender,args){rowIndex('" + index + "');}";
 }
}
JS:
function rowIndex(index)
{
 alert(index);
}

Thanks,
Princy.
0
Weilun
Top achievements
Rank 1
answered on 18 Jan 2012, 03:02 PM
Thanks a lot Princy.
It works and now my radgrid can edit product's quantity.
Tags
Grid
Asked by
Weilun
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Weilun
Top achievements
Rank 1
Share this question
or