Live Chat Icon For mobile
Live Chat Icon

How to access the BoundColumn information on SelectedIndexChanged event of a datagrid

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:BoundColumn Headertext='ProductId' DataField='Productid'></asp:BoundColumn>
	<asp:BoundColumn Headertext='ProductName' DataField='ProductName'></asp:BoundColumn>
</Columns>
</asp:DataGrid>

VB.NET


Protected Sub SelectedIndexChg(ByVal sender As Object, ByVal e As System.EventArgs)
	Label1.Text = DataGrid1.SelectedItem.Cells(1).Text & DataGrid1.SelectedItem.Cells(2).Text  
End Sub

C#


protected void SelectedIndexChg(object sender, System.EventArgs e)
{
        Label1.Text = DataGrid1.SelectedItem.Cells[1].Text + DataGrid1.SelectedItem.Cells[2].Text ;
}

Share with

Share on twitter
Share on facebook
Share on linkedin