<asp:DataGrid id='DataGrid1' OnItemCommand ='ItemCmd' AutoGenerateColumns =False runat='server'>
<Columns>
<asp:BoundColumn DataField='ProductID' HeaderText='ProductID'></asp:BoundColumn>
<asp:BoundColumn DataField='Productname' HeaderText='Productname'></asp:BoundColumn>
<asp:ButtonColumn DataTextField='Productid' CommandName='Show' HeaderText='Productid' ButtonType='PushButton'
Text='Click'></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
VB.NET
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
’Put user code to initialize the page here
If Not Page.IsPostBack Then
’Populate the DataGrid
End If
End Sub
Protected Sub ItemCmd(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
If e.CommandName = 'Show' Then
Response.Write(e.Item.Cells(1).Text)
End If
End Sub
C#
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack )
{
//Populate the DataGrid
}
}
protected void ItemCmd(Object source , System.Web.UI.WebControls.DataGridCommandEventArgs e )
{
if (e.CommandName.ToString () == 'Show')
{
Response.Write(e.Item.Cells[1].Text);
}
}
Share with