0
Answer

i m not able to bind the gridview on ddl's selected index

i m not able to bind the gridview on ddl's selected index change
 
public partial class Feedback_New : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TimeTracker_DevConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FillEmpDropdownList();
}
}
protected void FillEmpDropdownList()
{
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
cmd = new SqlCommand("[TT_GetFeedbackGoneDates_sp]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SupervisorID", "E1101");
adp.SelectCommand = cmd;
adp.Fill(dt);
DrpSelectDate.DataSource = dt;
DrpSelectDate.DataTextField = "FeedbackDate";
DrpSelectDate.DataValueField = "FeedbackDate";
DrpSelectDate.DataBind();
DrpSelectDate.Items.Insert(0, "-- Select --");
DrpSelectDate.Items.Insert(1, "hello");
//OR DrpSelectDate.Items.Insert(0, new ListItem("Select Emp Id", "-1"));
}
catch (Exception ex)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
cmd.Dispose();
adp.Dispose();
dt.Clear();
dt.Dispose();
}
}
protected void DrpSelectDate_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int ID = Convert.ToInt32(DrpSelectDate.SelectedValue);
BindEmpGrid(ID);
}
catch (Exception ex)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
}
private void BindEmpGrid(Int32 SupervisorID)
{
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
SqlCommand cmd = new SqlCommand("select * from TblEmployeeFeedBackDetail ");
adp.SelectCommand = cmd;
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
dgFeedback.DataSource = dt;
//lblEmpId.Text = "Emp Id :" + dt.Rows[0]["Emp_Id"].ToString();
//lblEmpName.Text = "Emp Name: " + dt.Rows[0]["EmpName"].ToString();
//lblCity.Text = "City: " + dt.Rows[0]["City"].ToString();
//lblSalary.Text = "Salary: " + dt.Rows[0]["Salary"].ToString();
dgFeedback.DataBind();
}
}
catch (Exception ex)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
dt.Clear();
dt.Dispose();//nalize and Dispose for releasing unmanaged resources like files, database connections, COM etc. This article helps you to understand the difference between Finalize and Dispose method.
adp.Dispose();
}
}
}