Hi ,
This Example will guide you .
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=IT-DEV2\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt from Items ";
SqlDataAdapter da = new SqlDataAdapter(statment, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string v1 = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
string v2 = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
string v3 = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
string v4 = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
SqlConnection con = new SqlConnection(@"Data Source=IT-DEV2\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
con.Open();
string statment = string.Format("insert into Items (Item_name, brand, size, section) values ('{0}' ,' {1}' , {2} , '{3}' )", v1,v2,Convert.ToInt32( v3),v4);
SqlCommand cmd = new SqlCommand(statment,con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
}
<div>
<asp:GridView ID="GridView1" runat="server"
onselectedindexchanging="GridView1_SelectedIndexChanging">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
</div>
Best Regards
M.Mitwalli