TextBox Id =TextBox1
Button Id =btCheck
Avaiable Label Id = lbAv //PageLoad Visible = false
Exists Label Id =lbExists // PageLoad Visible = false
Code Behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace EmailValidate
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button btCheck;
protected System.Web.UI.WebControls.Label lbAv;
protected System.Web.UI.WebControls.Label lbExists;
SqlConnection con = new SqlConnection(@"Server=servername;DataBase=DataBaseName;uid=sa;pwd=sa;");
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btCheck.Click += new System.EventHandler(this.btCheck_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btCheck_Click(object sender, System.EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter(" select * from ScrTest",con);
DataSet ds = new DataSet();
da.Fill(ds,"ScrTest");
DataView dv = new DataView(ds.Tables["ScrTest"]);/*Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation.*/
dv.RowFilter="emailid = '" + TextBox1.Text +"'";/*Gets or sets the expression used to filter which rows are viewed in the DataView*/
if(dv.Count >0)//If Count > 0 then Value Aavilable
{
lbExists.Visible=true;
lbAv.Visible=false;
}
else // Not Avaiable
{
lbAv.Visible=true;
lbExists.Visible=false;
}
}
}
}
DataBase Content
Avaiable Email Id
Exists Mail Id
No comments:
Post a Comment