TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
archana a
NA
2
0
problem with gridview
Dec 15 2007 4:20 PM
Hi Frineds,
This is my code for a simple gridview with edit,update,delete methods..
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
string connectionString = "server=system;Database=Sample;uid=sa;pwd=veena123";
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from Emp", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex; BindData();
}
protected void GridView1_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1; BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdatedEventArgs e)
{
Label lblEmpNo = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEmpNo") as Label;
TextBox txtName1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
TextBox txtSalary1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2") as TextBox;
TextBox txtDOB1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3") as TextBox;
TextBox txtDOTrans1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4") as TextBox;
TextBox txtDesignation1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox5") as TextBox;
TextBox txtDepartment1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox6") as TextBox;
String connectionString = "server=system;database=sample;uid=sa;pwd=veena123";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("Update emp set Emp_Name='" + txtName1.Text + "','" + txtSalary1.Text + "','" + txtDOB1.Text + "','" + txtDOTrans1.Text + "','" + txtDesignation1.Text + "','" + txtDepartment1.Text + "' where Emp_Number= '" + lblEmpNo.Text + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventHandler e)
{
Label lblEmpNo = (Label)GridView1.Rows[e.RowIndex].FindControl("lblEmpNo");
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
TextBox txtSalary = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");
TextBox txtDOB = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");
TextBox txtDOTrans = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");
TextBox txtDesignation = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox5");
TextBox txtDepartment = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox6");
string str ="delete from emp where Emp_Number='"+ lblEmpNo.Text +"'";
String connectionString = "server=system;database=sample;uid=sa;pwd=veena123";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand(str,con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
BindData();
}
}
But when i debug it i am getting an error saying that
System.Web.UI.WebControls.GridViewUpdatedEventArgs' doesnot contain a definition for 'RowIndex'
Can anyone plz let me know the problem...???
Bye,
Thanks in advance
Reply
Answers (
1
)
Load balancing with two web servers
onMouseover in DataList