hi,i have one empid textbox,when i enter the emplid in the teaxtbox,am displaying the payroll details of that particular emplid and am displying the gridview also by using "ontextchanged".table have these columns.....empid,empname,designation,department,DOJ,DOR,Basicsal,ot,....some like this...i cont put primary key for any column,because,when for every month we have payroll so id will berepeated,so i think to put the two extra columns as month and year.and i want give the year as primery key.i have created dropdownlist above emid text box,when i select the month and year from the dropdownlist,after that when i enter the empid in the text box,we need to retrieve that year that month payroll,please help me for dropdown selection code,please check my code i wrote like this,but i didn't write the code for dropdown ,i con't understand how to wrote it....
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace pay_description
{
public partial class paydescription : System.Web.UI.Page
{
// string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
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)";
TextBox24.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)
{
con.Open();
SqlCommand com = new SqlCommand("select * from payroll where EmployeeID='" + txtEmpid.Text + "', Month='"+DropDownList1.SelectedItem.Value+"' and Year='"+DropDownList2.SelectedItem.Value+"'", 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();
}
else
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
}
if (dr.HasRows)
{
GridView3.DataSource = dr;
GridView3.DataBind();
GridView2.Visible = false;
GridView3.Visible = true;
}
else
{
GridView3.Visible = false;
GridView2.Visible = false;
}
}
}
}
manimala