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

how to find control in click event

1 Answer 430 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
abinav
Top achievements
Rank 1
abinav asked on 18 Feb 2011, 05:02 AM
hi

i want to findcontrol of a textbox in radgrid itemtemplate in button event

i have done this but getting an exception
protected void btnSave_Click(object sender, EventArgs e)
{
        Button btnSave = (Button)sender; 
        GridHeaderItem item1 = ((GridHeaderItem)(btnSave.NamingContainer)); 
        RadNumericTextBox txtQty = (RadNumericTextBox)item1.FindControl("txtQty"); 
        RadNumericTextBox txtAmount = (RadNumericTextBox)item1.FindControl("txtAmount"); 
        RadNumericTextBox txtlicenseFee = (RadNumericTextBox)item1.FindControl("txtlicensefee");
}

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Feb 2011, 10:03 AM
Hello Abinav,

I suppose the Button and the other controls are in ItemTemplate.  If thats the case you can access the control using the findControl method.
Here is a sample code.

aspx:
<telerik:GridTemplateColumn HeaderText="TextBoxcol" UniqueName="TextBoxcol">
         <ItemTemplate>
                  <telerik:RadNumericTextBox ID="txtQty" runat="server" Value="11">
                  </telerik:RadNumericTextBox>
                  <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
        </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void Button2_Click(object sender, EventArgs e)
 {
     Button btnSave = (Button)sender;
     GridDataItem item1 = ((GridDataItem)(btnSave.NamingContainer));
     RadNumericTextBox txtQty = (RadNumericTextBox)item1.FindControl("txtQty");
    
 }

Thanks,
Shinu.
Tags
General Discussions
Asked by
abinav
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or