How to Bind data in gridview when Item selectd in DropdownList

Posted by Pintu08 under C# on 10/22/2013 | Points: 10 | Views : 1134 | Status : [Member] | Replies : 3
Hello Expert,
data not show on when ddlSupevisor Select in gridview
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();
}



}
}




Responses

Posted by: Shankul2784 on: 10/22/2013 [Member] Bronze | Points: 25

Up
0
Down
there is confusion between faculty and supervisor...there is no code written for supervisor... please check your code.

Thanks & Regards,

Shailesh

Pintu08, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pintu08 on: 10/22/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks Mr. Shailes

what confusion I have three ddl When I select 1st ddl 2nd will enabled and when I select 3rd ddl gridview will visible but When 3rd ddl i select gridview will not show what problem in above code please find and reply me.......

Pintu08, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/22/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Try this code:
highlighted part is the modification I have done with your code

protected void Page_Load(object sender, EventArgs e) 
{
if (!IsPostBack)
{
ddlFaculty.DataSource = GetData("spGetFaculty", null);
ddlFaculty.DataTextField = "ColumnNameWhichComesFronSP";
ddlFaculty.DataValueField = "ColumnNameWhichComesFronSP";
ddlFaculty.DataBind();

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.DataTextField = "ColumnNameWhichComesFronSP";
ddlSubject.DataValueField = "ColumnNameWhichComesFronSP";
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.DataTextField = "ColumnNameWhichComesFronSP";
ddlSupervisor.DataValueField = "ColumnNameWhichComesFronSP";
ddlSupervisor.DataBind();


ListItem liSupervisor = new ListItem("Select Supervisor", "-1");
ddlSupervisor.Items.Insert(0, liSupervisor);
}
}

protected void ddlSupervisor_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSupervisor.SelectedIndex == 0)
{
ddlSupervisor.SelectedIndex = 0;
ddlSupervisor.Enabled = false;
}
else
{
ThesisAwardGridView.Enabled = true;
LoadGirdView();
}
}

private void LoadGirdView()
{

SqlParameter parameter = new SqlParameter("@supervisorId", ddlSupervisor.SelectedValue);
DataSet DS = GetData("sp1GetThesisAwardedBySupervisorId", parameter);
ThesisAwardGridView.DataSource = DS;
ThesisAwardGridView.DataBind();
}

}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Pintu08, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response