Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
I solved to edit (update,clear,delete)the values in new page.
 
Erlier i was not kept quer string values in
(!Page.IsPostBack)
{
}
 
The following code is working well know.
 

protected void Page_Load(object sender, EventArgs e)
{
 
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("Manager");
DropDownList1.Items.Add("Assistant Manager");
DropDownList1.Items.Add("Sales Rep");
 
DropDownList2.Items.Add("Accounts");
DropDownList2.Items.Add("Sales");
}
 
if (!Page.IsPostBack)
{
string EmpNo = string.Empty;
if (!string.IsNullOrEmpty(Request.QueryString["EmpNo"]))
{
EmpNo = Request.QueryString["EmpNo"].ToString();
 
SqlConnection con = new SqlConnection("Server=**********;uid=sa;password=*******; database=sreeramdasari;");
SqlCommand cmd = new SqlCommand("select* from EmployeeDetails where EmpNo='" + EmpNo + "'", con);
con.Open();
cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
TextBox1.Text = EmpNo;
TextBox2.Text = sdr[1].ToString();
DropDownList1.SelectedValue = sdr[2].ToString().Trim();
DropDownList2.SelectedValue = sdr[3].ToString().Trim();
TextBox3.Text = sdr[4].ToString();
}
 
TextBox1.Enabled = false;
Button1.Enabled = false;
Button2.Enabled = true;
Button3.Enabled = true;
Button4.Enabled = true;
con.Close();
}
}
}

public void txtclear()
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
DropDownList1.SelectedIndex = -1;
DropDownList2.SelectedIndex=-1;
}
protected void Button1_Click(object sender, EventArgs e)
{
string EmpNo = TextBox1.Text;
string EmpName = TextBox2.Text;
string Designation = DropDownList1.SelectedItem.Text;
string Department = DropDownList2.SelectedItem.Text;
decimal Salary = Convert.ToDecimal(TextBox3.Text);

 
SqlConnection con = new SqlConnectio("Server=************;uid=sa;password=********; database=sreeramdasari;");
SqlCommand cmd = new SqlCommand("insert into EmployeeDetails values(@EmpNo,@EmpName,@Designation,@Department,@Salary)", con);
 
cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
cmd.Parameters.AddWithValue("@EmpName", EmpName);
cmd.Parameters.AddWithValue("@Designation", Designation);
cmd.Parameters.AddWithValue("@Department", Department);
cmd.Parameters.AddWithValue("@Salary", Salary);
con.Open();
 

int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Label6.Text = ("Record Added Successfuly");
}


else
{
Label6.Text = ("Record not Added");

}
Label6.Enabled = true;
Button2.Enabled = false;

con.Close();

}

protected void Button2_Click(object sender, EventArgs e)
{
txtclear();
Label6.Text=("Enter A New Record and Save");
TextBox1.Enabled = true;
Button1.Enabled = true;
Button3.Enabled = false;
Button4.Enabled = false;
}
protected void Button3_Click(object sender, EventArgs e)
 
{
string EmpNo = TextBox1.Text;
string EmpName = TextBox2.Text;
string Designation = DropDownList1.SelectedItem.Text;
string Department = DropDownList2.SelectedItem.Text;
decimal Salary = Convert.ToDecimal(TextBox3.Text);
 
if (!string.IsNullOrEmpty(Request.QueryString["EmpNo"]))
{
EmpNo = Request.QueryString["EmpNo"].ToString();
 
SqlConnection con = new SqlConnection("Server=*********;uid=sa;password=********; database=sreeramdasari;");
 
string query =("Update EmployeeDetails set EmpName=@EmpName,Designation=@Designation,Department=@Department,Salary=@Salary where EmpNo=@EmpNo");
 
String query = string.Empty;
query =("Update EmployeeDetails set EmpName=@EmpName, Designation=@Designation,Department=@Department,Salary=@Salary where EmpNo=@EmpNo", con);
sqlCommand cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.Text;
 

 
cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
cmd.Parameters.AddWithValue("@EmpName", EmpName);
cmd.Parameters.AddWithValue("@Designation", Designation);
cmd.Parameters.AddWithValue("@Department", Department);
cmd.Parameters.AddWithValue("@Salary", Salary);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
Label6.Text = (" Record Updated Successfully");
Label6.Enabled = true;
TextBox1.Enabled = false;
con.Close();
}
}
 


protected void Button4_Click(object sender, EventArgs e)
{
string EmpNo = TextBox1.Text;
SqlConnection con = new SqlConnection("Server=********;uid=sa;password=********; database=sreeramdasari;");
SqlCommand cmd = new SqlCommand("Delete from EmployeeDetails where EmpNo=@EmpNo", con);
 
con.Open();
cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
cmd.ExecuteNonQuery();
Label6.Text = (" Record Deleted Successfully");
Label6.Enabled = true;
TextBox1.Enabled = false;
txtclear();
con.Close();
}
}
Thanks&Regards
Sreeram
Posted 8-Nov-12 17:59pm
Edited 21-Nov-12 1:43am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check this out :
 

http://forums.asp.net/t/1058011.aspx/1/10[^]
 
http://blog.oscarscode.com/dot-net/redirect-to-another-page-with-javascript-in-asp-net/[^]
 
Apart from this, Create a linkbutton with Text = "" and write post-back (click event) method for that link button. In the postback event of linkbutton... write Response.Redirect("../xyz.aspx")
 
now call this from your javascript function.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 588
1 George Jonsson 258
2 CPallini 200
3 OriginalGriff 174
4 Shemeemsha RA 140
0 OriginalGriff 5,985
1 Sergey Alexandrovich Kryukov 5,341
2 CPallini 4,760
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100