.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

Row Updation in Gridview

Posted By: Dhilip.R     Posted Date: November 26, 2010    Points:2   Category :.NET Framework
Hi friends,

Can anybody tell me how to update row in gridview. I tried the following code

protected void gvstudent_SelectedRowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow newrow = gvstudent.Rows[e.RowIndex];

_name = (newrow.FindControl("txtname") as TextBox).Text;
_fees = (newrow.FindControl("txtfees") as TextBox).Text;
_rollno = txtrollnoinsert.Text;
repeter.updatestudent(_name, _fees, _rollno);
gvstudent.EditIndex = -1;
gridviewload();
}

But the following line are giving me the old value,how to get the new value, _name = (newrow.FindControl("txtname") as TextBox).Text; and _fees = (newrow.FindControl("txtfees") as TextBox).Text;


Responses
Author: Sajid P K             
Posted Date: November 29, 2010     Points: 5   
Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditText")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
ViewState["userid"] = Convert.ToInt32(e.CommandArgument.ToString());
paneladd.Visible = false;
paneledit.Visible = true;
panelshow.Visible = false;
if (con.State == ConnectionState.Closed)
con.Open();
queary = "select ID ,UserID,Password,Email,EntryDate,Status from tbluser where ID=" + id + "";
SqlCommand cmd = new SqlCommand(queary, con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
txtupuname.Text = dt.Rows[0][1].ToString();
txtuppassword.Text = dt.Rows[0][2].ToString();
txtupemail.Text = dt.Rows[0][3].ToString();

}
if (e.CommandName == "DeleteText")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
if (con.State == ConnectionState.Closed)
con.Open();
string delete = Convert.ToString(new SqlCommand("delete from tbluser where ID=" + id + "", con).ExecuteNonQuery());
string delete1 = Convert.ToString(new SqlCommand("delete from tbllogin where MemberID=" + id + "", con).ExecuteNonQuery());
show();
}
if (e.CommandName == "Deactive")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
if (con.State == ConnectionState.Closed)
con.Open();
string status = Convert.ToString(new SqlCommand("UPDATE tbluser set Status='0' where ID=" + id + "", con).ExecuteNonQuery());
string status1 = Convert.ToString(new SqlCommand("UPDATE tbllogin set Status='0' where MemberID=" + id + "", con).ExecuteNonQuery());
show();
}
if (e.CommandName == "active")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
if (con.State == ConnectionState.Closed)
con.Open();
string status = Convert.ToString(new SqlCommand("UPDATE tbluser set Status='1' where ID=" + id + "", con).ExecuteNonQuery());
string status1 = Convert.ToString(new SqlCommand("UPDATE tbllogin set Status='1' where MemberID=" + id + "", con).ExecuteNonQuery());
show();
}
}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend