Can you help me fix the code ..
In addition, I want to display with the timer the phrase "registration successfully" after saving or modifying
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dashbord.aspx.cs" Inherits="Login.Dashbord" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <style type="text/css">
- .auto-style1 {
- width: 100%;
- }
- .auto-style2 {
- }
- .auto-style3 {
- margin-left: 120px;
- }
- .auto-style4 {
- width: 22px;
- height: 27px;
- margin-left: 120px;
- }
- .auto-style5 {
- height: 27px;
- }
- .auto-style6 {
- margin-left: 120px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
-
- <table class="auto-style1">
- <tr>
- <td class="auto-style2" colspan="2"><strong>Save/Update</strong></td>
- </tr>
- <tr>
- <td class="auto-style6"></td>
- <td>
- <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="#33CC33" Text="Register Successfully"></asp:Label>
- </td>
- </tr>
- <tr>
- <td class="auto-style4">Name</td>
- <td class="auto-style5">
- <asp:TextBox ID="TextBox2" runat="server" Width="175px" ></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td class="auto-style6">Password</td>
- <td>
- <asp:TextBox ID="TextBox3" runat="server" Width="174px" ></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td class="auto-style6"> </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="auto-style3" colspan="2">
- <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="663px">
- <Columns>
- <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
- <asp:BoundField DataField="EMPNAME" HeaderText="EMPNAME" SortExpression="EMPNAME" />
- <asp:BoundField DataField="PASSWORD" HeaderText="PASSWORD" SortExpression="PASSWORD" />
- <asp:CommandField ShowSelectButton="True" />
- </Columns>
- </asp:GridView>
- </td>
- </tr>
- <tr>
- <td class="auto-style3" colspan="2">
- <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TblLoginConnectionString %>" OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT DISTINCT * FROM [tblUser]"></asp:SqlDataSource>
- </td>
- </tr>
- <tr>
- <td class="auto-style6" colspan="2">
- <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
- </td>
- </tr>
- </table>
- </div>
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" Width="115px" />
- <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Serach" Width="115px" />
- <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Update" Width="106px" />
- <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Delete" Width="113px" />
- </form>
- </body>
- </html>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
-
- namespace Login
- {
- public partial class Dashbord : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- }
-
- protected void Button1_Click(object sender, EventArgs e)
- {
- SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");
- SqlCommand cmd = new SqlCommand("insert into tblUser (EMPNAME,PASSWORD) values (@EMPNAME,@PASSWORD)", cn);
- cn.Open();
- cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);
- cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);
- cmd.ExecuteNonQuery();
- cn.Close();
- }
-
- protected void Button2_Click(object sender, EventArgs e)
- {
- SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");
- cn.Open();
- DataTable dt = new DataTable();
- SqlDataAdapter sd = new SqlDataAdapter("select EMPNAME,PASSWORD from tblUser where EMPNAME= '" +TextBox2.Text+"'", cn);
- sd.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- TextBox2.Text=Convert.ToString(dt.Rows[0]["EMPNAME"]);
- TextBox3.Text=Convert.ToString(dt.Rows[0]["PASSWORD"]);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- protected void Button3_Click(object sender, EventArgs e)
- {
- SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");
- SqlCommand cmd = new SqlCommand("Update tblUser set PASSWORD=@PASSWORD where EMPNAME=@EMPNAME", cn);
- cn.Open();
- cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);
- cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);
- cmd.ExecuteNonQuery();
- cn.Close();
-
- }
-
- protected void Button4_Click(object sender, EventArgs e)
- {
- SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");
- SqlCommand cmd = new SqlCommand("Delete from tblUser where EMPNAME=@EMPNAME", cn);
-
- cn.Open();
- TextBox2.Text = "";
- TextBox3.Text = "";
- cmd.ExecuteNonQuery();
-
- }
-
-
-
-
-
-
-
- protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");
- cn.Open();
- DataTable dt = new DataTable();
- SqlDataAdapter sd = new SqlDataAdapter("select EMPNAME,PASSWORD from tblUser where EMPNAME= '" + TextBox2.Text + "'", cn);
- sd.Fill(dt);
- if (dt.Rows.Count > 0)
- {
-
- GridView1.DataSource = tblUser;
- GridView1.DataBind();
- }
-
- }
-
- }
- }