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

Finding the RowIndex when RadComboBox fires inside ItemTemplate

2 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy Yoder
Top achievements
Rank 1
Jeremy Yoder asked on 08 Feb 2013, 10:50 PM

Here's my RadGrid...

<telerik:RadGrid ID="grdAssets"
    AllowPaging="True" runat="server" AllowSorting="True" AllowFilteringByColumn="true">
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
    <MasterTableView TableLayout="Fixed" ShowHeader="false" EditMode="PopUp"
            ClientDataKeyNames="AssetKey" DataKeyNames="AssetKey" >
 
        <Columns>
            <telerik:GridEditCommandColumn UniqueName="EditColumn">
            <HeaderStyle Width="70px" />
            <ItemStyle Width="70px" />
            </telerik:GridEditCommandColumn>
 
            <telerik:GridNumericColumn DataField="AssetKey" HeaderText="AssetKey"
                UniqueName="AssetKey" DataType="System.Int32" Visible="False" ReadOnly="True">
            </telerik:GridNumericColumn>
 
        </Columns>
 
        <ItemTemplate>
 
            <div>
 
                <telerik:RadComboBox ID="cbConditionID" runat="server" OnClientSelectedIndexChanged="onSelectedIndexChanged" Text='<%# Bind("ConditionID") %>'>
                    <Items>
                        <telerik:RadComboBoxItem Text="Excellent" Value="E" />
                        <telerik:RadComboBoxItem Text="Good" Value="G" />
                        <telerik:RadComboBoxItem Text="Fair" Value="F" />
                    </Items>
                </telerik:RadComboBox>
 
                <br />
 
                <span style="font-weight: bold; font-family: Arial Black;">AssetKey:</span>
                <%# Eval("AssetKey")%>
                <br/>
 
                <span style="font-weight: bold; font-family: Arial Black;">Description:</span>
                <%# Eval("AssetDescription")%>
                <br/>
                <span style="font-weight: bold;">Total Cost:</span>
                <%# Eval("TotalCost", "{0:C2}")%>
                <br/>
                <span style="font-weight: bold;">Quantity:</span>
                <%#Eval("Quantity") & " available"%>
                <br/>
            </div>
            <br/>
        </ItemTemplate>
 
        <EditFormSettings EditFormType="Template" CaptionFormatString="Edit Detail">
        <EditColumn UniqueName="EditCommandColumn1">
        </EditColumn>
 
        <FormTemplate>
            <br />
            <div style="margin-left:10px">
            <table border="0" cellpadding="2" cellspacing="2">
                <tr>
                    <td style="width:110px">
                        Asset Description
                    </td>
                    <td style="width:180px">
                        <telerik:RadTextBox ID="txtAssetDescription" runat="server" TabIndex="103" MaxLength="36"
                            Text='<%# Bind("AssetDescription") %>' Width="180px">
                        </telerik:RadTextBox>
                    </td>
                    <td style="width:40px">
                    </td>
                    <td style="width:110px">
                        Unit Cost
                    </td>
                    <td style="width:100px">
                        <telerik:RadNumericTextBox ID="txtUnitCost" runat="server" TabIndex="107" MaxLength="14"
                            NumberFormat-DecimalDigits="4" Culture="English (United States)"
                            DbValue='<%# Bind("UnitCost") %>' Width="100px">
                        </telerik:RadNumericTextBox>
                    </td>
                </tr>
 
 
                <tr style="height:25px">
                    <td colspan="5">
                    </td>
                </tr>
                <tr>
                    <td colspan="5">
                        <asp:ImageButton ID="imgSave" runat="server" TabIndex="120" AlternateText="OK"
                            ImageUrl="~/images/icons/save-24.jpg" ToolTip="OK"
                            CommandName='<%# IIf (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'
                            OnClientClick='return EditForm_Saved(this)' />
                             
                        <asp:ImageButton ID="imgCancel" runat="server" TabIndex="121" AlternateText="Cancel"
                            ImageUrl="~/images/icons/undo-24.jpg" ToolTip="Cancel" CommandName="Cancel" />
                    </td>
                </tr>
                <tr style="height:25px">
                    <td colspan="5">
                        <asp:Literal ID="litFormEditError" runat="server"></asp:Literal>
                    </td>
                </tr>
 
 
            </table>
            </div>
 
        </FormTemplate>
        <PopUpSettings Modal="True" Width="620px" Height="300px" />
        </EditFormSettings>
 
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true">
        </Scrolling>
        <Selecting AllowRowSelect="false" />
    </ClientSettings>
</telerik:RadGrid>



As you can see, within the ItemTemplate, I have a RadComboBox that fires OnClientSelectedIndexChanged. Here's my function...

function onSelectedIndexChanged(sender, eventArgs) {
    // How can I access the row index where RadComboBox is located?
}

It fires, but within it, how can I determine the grid row index where the RadComboBox resides? Also, in general, is there anything wrong with how I have my RadGrid setup? Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Feb 2013, 02:21 PM
Hello,

Please try with below code snippet.
function ClientSelectedIndexChanged(sender, args) {
               alert(sender.get_attributes().getAttribute("CurrentRowIndex"));
           }
<Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="ClientSelectedIndexChanged">
                               <Items>
                                   <telerik:RadComboBoxItem Text="1" Value="1" />
                                   <telerik:RadComboBoxItem Text="2" Value="2" />
                               </Items>
                           </telerik:RadComboBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
               </Columns>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        RadComboBox RadComboBox1 = item.FindControl("RadComboBox1") as RadComboBox;
        RadComboBox1.Attributes.Add("CurrentRowIndex",item.ItemIndex.ToString());
    }
 
   
}


Thanks,
Jayesh Goyani
0
Jeremy Yoder
Top achievements
Rank 1
answered on 11 Feb 2013, 05:43 PM

Brilliant! Worked like a charm! Thanks much!

BTW, in general, is my RadGrid OK? Seems like I'm trying to do a lot with it, and I'm wondering if certain elements will clash.
Tags
Grid
Asked by
Jeremy Yoder
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jeremy Yoder
Top achievements
Rank 1
Share this question
or