hi here is the code as per ur requirement.
gridview.aspx design page
<asp:gridview id="GridView1" runat="server" datakeynames="ID" xmlns:asp="#unknown">
onrowcommand="GridView1_RowCommand">
<columns>
<asp:buttonfield commandname="View" text="View" /;
</columns>
</asp:gridview>
<u>gridview.aspx.cs page</u>
#region Bind GridView();
private void BindGridView()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
try
{
connection.Open();
string sqlStatement = "SELECT * FROM Registration";
SqlCommand cmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
if (dt.Rows.Count; 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
catch (SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
#endregion
this code for gridview1_RowCommand:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
int index = Convert.ToInt32(e.CommandArgument);
int id = Convert.ToInt32(GridView1.DataKeys[index].Value);
Response.Redirect("ViewinTextbox.aspx?UserID=" + id);
}
}
viewinTextbox.aspx
place here text box field
then in viewintexbox.aspx.cs give this code in page load.
string sID = Request.QueryString["UserID"].ToString();
int id = 0;
int.TryParse(sID, out id);
SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());
con.Open();
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="usp_view";
SqlParameter paraFirstName = new SqlParameter("@ID", SqlDbType.NVarChar);
paraFirstName.Value=id;
cmd.Parameters.Add(paraFirstName);
SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sqlDA.Fill(dt);
if (dt.Rows.Count; 0)
{
textboxFirstName.Text = dt.Rows[0]["FirstName"].ToString();
textboxMiddlename.Text = dt.Rows[0]["MiddleName"].ToString();
}
here is stored procedure query
create PROCEDURE usp_view
@ID int
AS
SELECT * from [tableName] where ID=@ID
it will work 100% .accept solution.