I have a webform in asp.net.In that webform there is 2
division class(DIV).in one of the div class there is a text
box for enter the id & a button for to check id with
database value.My doubt is that how can i appear the 2nd
Div contents only when the id is true with database
value.if wrong do not display the div . i Want code in c#.

Answer Posted / jyothis

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string flag;
object dsd;
flag= setconnection();
if (flag=="True" )
{
dsd = getconnection();
MyDiv.Visible=true;
GridView1.DataSource = dsd;
GridView1.DataBind();
}

}
public object getconnection()
{
String constr =
ConfigurationManager.ConnectionStrings["ConnectDBString"].ConnectionString;
SqlConnection con = new SqlConnection();
con.ConnectionString = constr;

String query = "SELECT * FROM EMPLOYEE WHERE
EmployeeName = '" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();

DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds,"EMPLOYEE");
return (ds);

con.Close();

}
public string setconnection()
{
String constr =
ConfigurationManager.ConnectionStrings["ConnectDBString"].ConnectionString;
SqlConnection con = new SqlConnection();
con.ConnectionString=constr;

String query = "SELECT * FROM EMPLOYEE WHERE
EmployeeName = '" + TextBox1.Text + "'";
SqlCommand cmd =new SqlCommand();
cmd.CommandText= query;
cmd.Connection=con;
con.Open();
string hd;
hd="False";
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{

int ID = (int)dr["ID"];
string Name = (string)dr["EmployeeName"];
}
if (dr.FieldCount >1)
{
hd="True";

}
}

return(hd);
con.Close();

}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Elaborate differentiation between Cache and Application?

532


Explain login controls.

612


What is the difference between page directive include and action tag include?

521


What is cache in asp net?

527


Explain the difference between asp.net mvc and asp.net webforms? : asp.net mvc

525






What is the difference between debug and release?

518


Define static constructor?

552


What is the mvc framework?

562


What is asp net_sessionid?

637


In a Repeater control how one can provide an alternating color scheme ?

560


What is jade template engine?

572


Can a master page have more than one contentplaceholder?

504


What is a windows service?

553


What is the question mark in a url?

516


How do you hide the columns?

590