how to Fire Button Click Event in Gridview Control.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 4220
hi
I have post the sample for how to Fire Button Click Event in Gridview Control.

Client Side Code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px" OnRowCommand="GridView1_RowCommand"
CellPadding="4" DataKeyNames="ProductID"
ForeColor="#333333">

<Columns>

<asp:BoundField DataField="ProductID" HeaderText="ProductID"
SortExpression="ProductID" />

<asp:ButtonField ButtonType="link" CommandName="ProductName"
DataTextField="ProductName" HeaderText="Name"
SortExpression="ProductName" />

<asp:ButtonField ButtonType="button" CommandName="MoreDetail"
HeaderText="More Details" Text="More Details" />

<asp:ButtonField ButtonType="Link" CommandName="ViewCategory"
HeaderText="View Category" Text="View Category" />





</Columns>

</asp:GridView>


Server Side Code

protected void GridView1_RowCommand(object sender,System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
string currentCommand = e.CommandName;
int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
string ProductID = GridView1.DataKeys[currentRowIndex].Value.ToString();
}

Comments or Responses

Login to post response