本文介绍了如何在DropdownList中选择项目时在gridview中绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Expert(s),
我有三(3)个下拉列表(ddl),
当用户选择第一个ddl时,第二个ddl将被启用,当第三个ddl被选中时,Gridview将在第三个ddl ID的基础上可见.I在第三个ddl完成我的任务但是当我在第三个ddl中选择项目时,gridview没有显示。请帮我知道答案。请回复我。谢谢提前!!!!!
我的代码背后如下:
Hello Expert(s),
I have Three(3) dropdownLists(ddl),
When User Select 1st ddl, 2nd ddl will be enabled and when 3rd ddl is selected than Gridview will be visible on bases of 3rd ddl's ID .I Completed my task at 3rd ddl but when I select item in 3rd ddl gridview is not getting visible .Please help me who knows answer.please reply me .thanks In Advance!!!!!
My Code Behind are given below:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlFaculty.DataSource = GetData("spGetFaculty", null);
ddlFaculty.DataBind();
ListItem liFaculty = new ListItem("Select Faculty", "-1");
ddlFaculty.Items.Insert(0, liFaculty);
ListItem liSubject = new ListItem("Select Subject", "-1");
ddlSubject.Items.Insert(0, liSubject);
ListItem liSupervisor = new ListItem("Select Supervisor", "-1");
ddlSupervisor.Items.Insert(0, liSupervisor);
ddlSubject.Enabled = false;
ddlSupervisor.Enabled = false;
//ThesisAwardGridView.Visible = false;
}
}
private DataSet GetData(string SPName, SqlParameter SPParam)
{
string cs = ConfigurationManager.ConnectionStrings["DPSMLSU"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
SqlDataAdapter da = new SqlDataAdapter(SPName, con);
DataTable dt = new DataTable();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
if (SPParam != null)
{
da.SelectCommand.Parameters.Add(SPParam);
}
DataSet DS = new DataSet();
da.Fill(DS);
return DS;
}
protected void ddlFaculty_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlFaculty.SelectedIndex == 0)
{
ddlSubject.SelectedIndex = 0;
ddlSubject.Enabled = false;
ddlSupervisor.SelectedIndex = 0;
ddlSupervisor.Enabled = false;
}
else
{
ddlSubject.Enabled = true;
SqlParameter parameter = new SqlParameter("@FacultyId ", ddlFaculty.SelectedValue);
DataSet DS = GetData("spGetSubjectByFacultyId", parameter);
ddlSubject.DataSource = DS;
ddlSubject.DataBind();
ListItem liSubject = new ListItem("Select Subject", "-1");
ddlSubject.Items.Insert(0, liSubject);
ddlSupervisor.SelectedIndex = 0;
ddlSupervisor.Enabled = false;
}
}
protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSubject.SelectedIndex == 0)
{
ddlSupervisor.SelectedIndex = 0;
ddlSupervisor.Enabled = false;
}
else
{
ddlSupervisor.Enabled = true;
SqlParameter parameter = new SqlParameter("@SubjectId ", ddlSubject.SelectedValue);
DataSet DS = GetData("spGetSupervisorListBySubjectId ", parameter);
ddlSupervisor.DataSource = DS;
ddlSupervisor.DataBind();
ListItem liSupervisor = new ListItem("Select Supervisor", "-1");
ddlSupervisor.Items.Insert(0, liSupervisor);
LoadGirdView();
}
}
private void LoadGirdView()
{
SqlParameter parameter = new SqlParameter("@supervisorId", ddlSupervisor.SelectedValue);
DataSet DS = GetData("sp1GetThesisAwardedBySupervisorId", parameter);
ThesisAwardGridView.DataSource = DS;
ThesisAwardGridView.DataBind();
}
}
}
推荐答案
protected void ddlSupervisor_selectedindexchanged (object sender, EventArgs e)
{
LoadGirdView();
}
这篇关于如何在DropdownList中选择项目时在gridview中绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!