Live Chat Icon For mobile
Live Chat Icon

How to access information from the controls in the TemplateColumn in SelectedIndexChanged Event

Platform: ASP.NET| Category: DataGrid

<asp:Label id='Label1' runat='server'>Label</asp:Label>
<asp:DataGrid id='DataGrid1' OnSelectedIndexChanged='SelectedIndexChg' AutoGenerateColumns='False' runat='server'>
<Columns>
	<asp:ButtonColumn Text='Select' ButtonType='PushButton' CommandName='Select'></asp:ButtonColumn>
	<asp:TemplateColumn HeaderText='ProductId'>
		<ItemTemplate>
			<asp:Label text=<%#DataBinder.Eval(Container.DataItem , 'Productid')%> ID='lbl1' Runat=server ></asp:Label>
		</ItemTemplate>
	</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

VB.NET


Protected Sub SelectedIndexChg(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = CType(DataGrid1.SelectedItem.FindControl('lbl1'), Label).Text
    End Sub

C#


protected void SelectedIndexChg(object sender, System.EventArgs e)
{
        Label1.Text =  ((Label)DataGrid1.SelectedItem.FindControl ('lbl1')).Text ;
}

Share with

Share on twitter
Share on facebook
Share on linkedin