how to get gridview with ontextchanged="txtEmpid_TextChanged"?

Posted by Tejamanimala under C# on 10/17/2013 | Points: 10 | Views : 840 | Status : [Member] | Replies : 3
hi i have a application,in that when i enter the employee id in textbox,i want to get the data from database,to display it in a some textboxes.like i want to get the pay roll from db into textboxes,that are designation,department,basic salary netamount.it is working,my problem is when i enter the employee id in the textbox also want to display the gridview of a that particular id employee,but am not geting it,i tried it but its not working,please check my code and tell me what should i do?

here is the code...

SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;Data Source=EKTHA-3D34;Initial Catalog=Ektha");
protected void Page_Load(object sender, EventArgs e)
{

txtEmpid.Attributes["onclick"] = "clearTextBox(this.id)";
GridView2.Visible = true;
Label1.Text = Session["UserID"].ToString();
getName();

}

private void getName()
{
// SqlConnection con = new SqlConnection(strcon);
con.Open();

SqlCommand cmd = new SqlCommand("select Name from Admin where UserID ='" + Label1.Text + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
string name = "";
try
{
if (dr.Read())
{
name = dr["Name"].ToString();

lblName.Text = name;
}
dr.Close();
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
}

finally
{
con.Close();
}
}

protected void txtEmpid_TextChanged(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(strcon);
con.Open();

SqlCommand com = new SqlCommand("select * from payroll where EmployeeID='" + txtEmpid.Text + " ' ", con);
SqlDataReader dr;
dr = com.ExecuteReader();

if (dr.Read())
{
TextBox24.Text = dr["EmpName"].ToString();
TextBox1.Text = dr["Department"].ToString();
TextBox2.Text = dr["DOJ"].ToString();
TextBox3.Text = dr["BasicSalary"].ToString();
TextBox4.Text = dr["Designation"].ToString();
TextBox5.Text = dr["DOR"].ToString();
TextBox6.Text = dr["NetAmt"].ToString();
GridView2.Visible = false;
GridView3.Visible = true;
}
else
{

TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}

}


}

manimala


Responses

Posted by: Nismeh on: 10/18/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Firstly check property of text box AutoPost back must be true. And one more suggestion. Best way to perform this action is you should use WebService for effective output.

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 10/18/2013 [Member] Starter | Points: 25

Up
0
Down
mismeh thank you,but i put the same proprty,and i dont know webservices,how to use webservice for this?because am new to this dotnet

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 10/18/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Web Service is nothing much but simply game of configuration and some keywords. Please follow following link in which I've described steps for creating web service.

http://nishantkumarmehta.blogspot.in/2012/12/web-serivces.html

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response