How to use a LinkButton in a DataGrid

Platform: ASP.NET| Category: DataGrid

<asp:DataGrid id='DataGrid1' OnItemCommand='ItemCmd' runat='server'>
	<Columns>
		<asp:ButtonColumn DataTextField='ProductID' CommandName='Show' HeaderText='Productid' ButtonType='LinkButton'
		Text='Click'></asp:ButtonColumn>
	</Columns>
</asp:DataGrid>

VB.NET


Protected Sub ItemCmd(source As Object, e As System.Web.UI.WebControls.DataGridCommandEventArgs)
   If e.CommandName.ToString() = 'Show' Then
      Response.Write(e.Item.Cells(5).Text)
   End If
End Sub ’ItemCmd

C#


protected void ItemCmd(Object source, System.Web.UI.WebControls.DataGridCommandEventArgs e   ) 
{ 
	if (e.CommandName.ToString () == 'Show')
	{
		Response.Write(  e.Item.Cells[5].Text  );
	}
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.