Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this is aspx.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- public partial class phoneLostData : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Button b1 = sender as Button;
- try
- {
- string dbAddress = @"Data Source=.SQLEXPRESS;AttachDbFilename=D:mcasem5sem5ProjectApp_DataDatabase.mdf;Integrated Security=True;User Instance=True; MultipleActiveResultSets=True;";
- SqlConnection myCon = new SqlConnection(dbAddress);
- myCon.Open();
- string q1 = "select complainerName,status from lostPhnFir";
- SqlCommand myCmd = new SqlCommand(q1, myCon);
- SqlDataReader readIt = myCmd.ExecuteReader();
- while (readIt.Read())
- {
- // Response.Write("alert('hi')");
- if (readIt["complainerName"].Equals("abc") && readIt["status"].Equals("Checked"))
- {
- b1.Text = "Checked";
- b1.Enabled = false;
- }
- }
- readIt.Close();
- myCon.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- public void Button1(object sender, EventArgs e)
- {
- Button b1 = sender as Button; // I want to use this b1 to page_load
- string dbAddress = @"Data Source=.SQLEXPRESS;AttachDbFilename=D:mcasem5sem5ProjectApp_DataDatabase.mdf;Integrated Security=True;User Instance=True; MultipleActiveResultSets=True;";
- SqlConnection myCon = new SqlConnection(dbAddress);
- myCon.Open();
- string q1 = "select complainerName from lostPhnFir";
- int flag = 0;
- SqlCommand myCmd = new SqlCommand(q1, myCon);
- SqlDataReader readIt = myCmd.ExecuteReader();
- if (b1.ID == "btnFIRLodge")
- {
- b1.Text = "Checked";
- b1.Enabled = false;
- flag = 1;
- }
- if (flag == 1)
- {
- string status1 = "Checked";
- string s1 = "abc";
- string sql = "update lostPhnFir set status='" + status1 + "' where complainerName='" + s1 + "'";
- SqlCommand myCmd2 = new SqlCommand(sql, myCon);
- myCmd2.ExecuteNonQuery();
- }
- }
- //this is aspx.
- <asp:TemplateField HeaderText="FIR Lodged" ShowHeader="False">
- <ItemTemplate>
- <asp:Button ID="btnFIRLodge" runat="server"
- Text="Send Message" onclick="Button1"></asp:Button>
- </ItemTemplate>
- </asp:TemplateField>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement