Guest User

Untitled

a guest
Jan 19th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. public partial class Pages_Managingpayment : System.Web.UI.Page
  2. {
  3. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyServer"].ConnectionString);
  4. protected void Page_Load(object sender, EventArgs e)
  5. {
  6.  
  7. if(IsPostBack)
  8. {
  9. Load();
  10. }
  11. }
  12. protected void Load() {
  13. DataSet ds = new DataSet();
  14. ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
  15. GridView1.DataSource = ds;
  16. GridView1.DataBind();
  17. int columncount = GridView1.Rows[0].Cells.Count;
  18. GridView1.Rows[0].Cells.Clear();
  19. GridView1.Rows[0].Cells.Add(new TableCell());
  20. GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
  21. GridView1.Rows[0].Cells[0].Text = "No records on display";
  22. }
  23. protected void SearchButton_Click(object sender, EventArgs e)
  24. {
  25. if (IsPostBack)
  26. {
  27. BindEmployeeDetails();
  28. }
  29. }
  30. protected void BindEmployeeDetails()
  31. {
  32. con.Open();
  33. SqlCommand cmd = new SqlCommand("Select * from users", con);
  34. SqlDataAdapter da = new SqlDataAdapter(cmd);
  35. DataSet ds = new DataSet();
  36. da.Fill(ds);
  37. con.Close();
  38. if (ds.Tables[0].Rows.Count > 0)
  39. {
  40. GridView1.DataSource = ds;
  41. GridView1.DataBind();
  42. }
  43. else
  44. {
  45. ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
  46. GridView1.DataSource = ds;
  47. GridView1.DataBind();
  48. int columncount = GridView1.Rows[0].Cells.Count;
  49. GridView1.Rows[0].Cells.Clear();
  50. GridView1.Rows[0].Cells.Add(new TableCell());
  51. GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
  52. GridView1.Rows[0].Cells[0].Text = "No Records Found";
  53. }
  54. }
  55. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  56. {
  57. GridView1.EditIndex = e.NewEditIndex;
  58. BindEmployeeDetails();
  59. }
  60. protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  61. {
  62. //int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
  63. string passwords = GridView1.DataKeys[e.RowIndex].Value.ToString();
  64. TextBox pass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Password");
  65. TextBox usernames = (TextBox)GridView1.Rows[e.RowIndex].FindControl("username");
  66. TextBox usertypes = (TextBox)GridView1.Rows[e.RowIndex].FindControl("usertype");
  67. con.Open();
  68. SqlCommand cmd = new SqlCommand("update users set User_Type='" + usertypes.Text + "',Username='" + usernames.Text + "' where password='" + passwords + "'", con);
  69. cmd.ExecuteNonQuery();
  70. con.Close();
  71. //.ForeColor = Color.Green;
  72. //lblresult.Text = username + " Details Updated successfully";
  73. GridView1.EditIndex = -1;
  74. BindEmployeeDetails();
  75. }
  76. protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  77. {
  78. GridView1.EditIndex = -1;
  79. BindEmployeeDetails();
  80. }
  81. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  82. {
  83. //int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["UserId"].ToString());
  84. string passwords = GridView1.DataKeys[e.RowIndex].Values["password"].ToString();
  85. con.Open();
  86. SqlCommand cmd = new SqlCommand("delete from users where password='" + passwords + "'", con);
  87. int result = cmd.ExecuteNonQuery();
  88. con.Close();
  89. if (result == 1)
  90. {
  91. BindEmployeeDetails();
  92. // lblresult.ForeColor = Color.Red;
  93. //lblresult.Text = username + " details deleted successfully";
  94. }
  95. }
  96. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  97. {
  98. if (e.CommandName.Equals("AddNew"))
  99. {
  100. TextBox usertypes = (TextBox)GridView1.FooterRow.FindControl("usertype");
  101. TextBox usernames = (TextBox)GridView1.FooterRow.FindControl("username");
  102. TextBox passwords = (TextBox)GridView1.FooterRow.FindControl("password");
  103. con.Open();
  104. SqlCommand cmd =
  105. new SqlCommand(
  106. "insert into users values('" + usertypes.Text + "','" +
  107. usernames.Text + "','" + passwords.Text + "')", con);
  108. int result = cmd.ExecuteNonQuery();
  109. con.Close();
  110. if (result == 1)
  111. {
  112. BindEmployeeDetails();
  113. // lblresult.ForeColor = Color.Green;
  114. //lblresult.Text = txtUsrname.Text + " Details inserted successfully";
  115. }
  116. else
  117. {
  118. //lblresult.ForeColor = Color.Red;
  119. //lblresult.Text = txtUsrname.Text + " Details not inserted";
  120. }
  121. }
  122. }
  123.  
  124. DataSet ds = new DataSet();
  125. ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
  126.  
  127. protected void Load() {
  128. DataSet ds = new DataSet();
  129. if(ds.Tables.Count == 0)
  130. {
  131. // Syntax might be wrong. I am trying to add new table if it is missing.
  132. ds.Table.Add(new Table());
  133. }
  134. ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
  135. GridView1.DataSource = ds;
  136. GridView1.DataBind();
  137. int columncount = GridView1.Rows[0].Cells.Count;
  138. GridView1.Rows[0].Cells.Clear();
  139. GridView1.Rows[0].Cells.Add(new TableCell());
  140. GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
  141. GridView1.Rows[0].Cells[0].Text = "No records on display";
  142. }
Add Comment
Please, Sign In to add comment