Advertisements

Archive

Posts Tagged ‘findcontrol’

GridView: Findcontrol from HeaderTemplate/ItemTemplate

September 19, 2017 Leave a comment

How to find item template control in GridView?

Dim chkHeader As CheckBox = DirectCast(gridView1.Row.FindControl(“chkHeader”), CheckBox)

How to find control from header template in grid view?

For example If you want to find checkbox available in header template of gridview

<asp:GridView ID=”gridView1″ runat=”server” AutoGenerateColumns=”False”><Columns>

<asp:TemplateField >

<HeaderTemplate>

<asp:CheckBox ID=”chkHeader” runat=”server” />

 </HeaderTemplate>

</asp:TemplateField >

</Columns>

</asp:GridView>

Solution:

Find Header control using following line of code

VB.NET Code:

Dim chkHeader As CheckBox = DirectCast(gridView1.HeaderRow.FindControl(“chkHeader”), CheckBox)

C# Code:

CheckBox chkHeader = (CheckBox)gridView1.HeaderRow.FindControl(“chkHeader”);

Hope this is help !

 

 

 

 

 

Advertisements

How to find control with in repeater on button click event

December 10, 2013 Leave a comment

<asp:Repeater ID=”RptInfo” runat=”server”>

<ItemTemplate>

<asp:Panel ID=”pnlReadonly” runat=”server”>

….

</asp:Panel>

</ItemTemplate>

</asp:Repeater>

Code : 

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

Dim pnlReadonly As Panel = DirectCast(RptSoccerInfo.Items(0).FindControl(“pnlReadonly”), Panel)

If (Not pnl Is Nothing) Then
‘ some code
End If

End Sub

Will add some more detail soon .