using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class tbbt : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["emp_dbConnectionString"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindEmpGrid(); } } protected void ddlEmpRecord_SelectedIndexChanged(object sender, EventArgs e) { try { BindEmpGrid(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true); } } private void BindEmpGrid() { DataTable dt = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(); try { SqlCommand cmd = new SqlCommand("select * from shakhes where month=" + ddlEmpRecord.Text + " ", con); adp.SelectCommand = cmd; adp.Fill(dt); if (dt.Rows.Count > 0) { grdEmp.DataSource = dt; lblsalary.Text = "salary: " + dt.Rows[0]["salary"].ToString(); lblyear.Text = "year :" + dt.Rows[0]["year"].ToString(); lblmonth.Text = "month: " + dt.Rows[0]["month"].ToString(); grdEmp.DataBind(); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true); } finally { dt.Clear(); dt.Dispose(); adp.Dispose(); } } protected void ddlEmpRecord_TextChanged(object sender, EventArgs e) { BindEmpGrid(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)