TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
arunesh trivedi
NA
5
1.3k
i m not able to bind the gridview on ddl's selected index
Jun 30 2016 7:35 AM
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();
}
}
}
Reply
Answers (
0
)
Openxml export to word .net c#
Problem with tempdata