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

Find Controls in InsertItemTemplate

1 Answer 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
-Tony
Top achievements
Rank 1
-Tony asked on 30 Apr 2013, 06:40 PM

How would I got about finding controls in the Insert Item template without using the Item Databound Event? I want to be able to find the controls within a radio button list _SelectedIndexChanged event. I was able to do this with controls inside the EditTemplate:

Protected Sub rblEdit_SelectedIndexChanged(sender As Object, e As EventArgs)
     
       For Each item As GridItem In RadGrid1.MasterTableView.Items
           If item.Edit Then
               Dim editItem As GridEditFormItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem(item.ItemIndex), GridEditFormItem)
               Dim DDList As DropDownList = DirectCast(editItem.FindControl("ddlEdit"), DropDownList)
               Dim RBLEdit As RadioButtonList = DirectCast(editItem.FindControl("rblEdit"), RadioButtonList)
               Dim bTextBox As TextBox = DirectCast(editItem.FindControl("BTextbox"), TextBox)
               Dim LBLPercent As Label = DirectCast(editItem.FindControl("lblPercent"), Label)
               If RBLEdit.SelectedValue = "No" Then
                   DDList.Visible = False
                   LBLPercent.Visible = False
                   bTextBox.ForeColor = Drawing.Color.DarkRed
               ElseIf RBLEdit.SelectedValue = "Yes" Then
                   bTextBox.ForeColor = Drawing.Color.Green
                   DDList.Visible = True
                   LBLPercent.Visible = True
               End If
 
           End If
 
       Next
 
   End Sub

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 01 May 2013, 07:57 AM
Hello,

Please try with the below code snippet.
<MasterTableView EditMode="InPlace"">
                <Columns>
                    <telerik:GridTemplateColumn>
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem item in RadGrid1.EditItems)
       {
           GridEditableItem itemToEdit = (item.OwnerTableView.EditMode == GridEditMode.InPlace) ? (GridEditableItem)item : (GridEditableItem)item.EditFormItem;
 
           string strText = (itemToEdit.FindControl("TextBox1") as TextBox).Text;
 
       }
   }
Protected Sub Button1_Click(sender As Object, e As EventArgs)
    For Each item As GridDataItem In RadGrid1.EditItems
        Dim itemToEdit As GridEditableItem = If((item.OwnerTableView.EditMode = GridEditMode.InPlace), DirectCast(item, GridEditableItem), DirectCast(item.EditFormItem, GridEditableItem))
 
 
        Dim strText As String = TryCast(itemToEdit.FindControl("TextBox1"), TextBox).Text
    Next
End Sub


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
-Tony
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or