I have a grid in .aspx page where is three text fields like name
,id
,role
and there is also one edit button where you click the value of this row will show in txtname,txtid,txtroll
This value i want to update and insert into database.
I have a grid in .aspx page where is three text fields like name
,id
,role
and there is also one edit button where you click the value of this row will show in txtname,txtid,txtroll
This value i want to update and insert into database.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
string uname = "";
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
TextBox txtbox1_val = (TextBox)row.FindControl("TxtChangeActive");
uname = Server.HtmlDecode(row.Cells[1].Text.ToString());
string upd_query = "update login set active='" + txtbox1_val.Text + "' where uname='" + uname + "' ";
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand(upd_query, con);
cmd.ExecuteNonQuery();
string query_login = "select * from Login";
SqlDataAdapter da_login = new SqlDataAdapter(query_login, con);
DataSet ds_login = new DataSet();
da_login.Fill(ds_login);
GridView1.DataSource = ds_login;
GridView1.DataBind();
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
}
In Design page
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand"
AlternatingRowStyle-BackColor="#006699"
AlternatingRowStyle-ForeColor="#FFFFFF" onrowupdating="GridView1_RowUpdating">
<Columns >
<asp:BoundField HeaderText="Name" DataField="uname" />
<asp:BoundField HeaderText="Pass" DataField="upass"/>
<asp:TemplateField>
<HeaderTemplate>Active</HeaderTemplate>
<ItemTemplate >
<asp:TextBox ID="TxtChangeActive" runat="server" Text='<%#Eval("active")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Update" Text="Update" />
</Columns>
</asp:GridView>