how to update the value in gridview?

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.

Answers


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>

Need Your Help

Importing partial data into MySQL from CSV

mysql csv

I have a CSV that is a partial projection of an origin table. I have the same table structure in my DB.

How can I change my system colors to default?

c++ windows winapi

In my C++ application I wrongly changed system color:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.