In gridview how to use rowcommand event for a button
I am using a gridview in aspx and i have two pages that registration and details.aspx once registration completed it should goto details page in details.aspx i have kept a gridview in that GV i am supposed be use row command event for a button it should show the all the rsults for the students with the edit button as the last column for all the students i used item template for that. but in row command event i dont know the function to write if user clicking edit it should goto the edit page using the userid the id should be noon editable mode and other fields can editable.Gridview(Details.aspx)
details.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web.Configuration.Common;
public partial class GridView_Practice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connection2 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connection1"].ConnectionString;
SqlConnection con = new SqlConnection(connection2);
con.Open();
SqlCommand cmd = new SqlCommand("select * from User_Information", con);
SqlDataReader rdr = cmd.ExecuteReader();
GridView3.DataSource = rdr;
GridView3.DataBind();
con.Close();
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Khan Abrar AhmedPosted Jul 16, 2014, 2:32 AM
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
try
{
int userid= Convert.ToInt32(e.CommandArgument);
//response redirect to your edit page and in the query string pass the user id as paramter
}
catch (Exception ex)
{ AppException.HandleException(ex); }
}
}
and also refer
http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/
http://www.c-sharpcorner.com/uploadfile/raj1979/select-add-update-and-delete-data-in-a-Asp-Net-gridview-control/
Abhay ShankerPosted Jul 16, 2014, 2:29 AM
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand(v=vs.110).aspx
http://www.c-sharpcorner.com/uploadfile/syedshakeer/rowcommand-event-in-gridview/
http://www.codeproject.com/Tips/564619/Example-of-gridview-rowcommand-on-Button-Click
http://www.dotnetlearners.com/blogs/view/67/Aspnet-Grid-view-Row-command-Event.aspx