This is code in aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false" LoadScriptsBeforeUI="false" ScriptMode="Release"></asp:ScriptManager>
<div align="center">
<asp:SqlDataSource ID="sqlDataSourceScholarship" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM Scholarship ORDER BY Scholarship ASC"></asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Width="130px" Text="Scholarship :"></asp:Label>
<asp:DropDownList ID="ddlScholarship" DataSourceID="sqlDataSourceScholarship" DataTextField="Scholarship" DataValueField="ScholarshipID" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="330px">
<asp:ListItem >SELECT SCHOLARSHIP NAME</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Label ID="lblSearch" runat="server" Font-Bold="True" Width="90px" Text="Search Type :"></asp:Label>
<asp:DropDownList ID="ddlSearch" runat="server" Style="margin-left: 27px" AutoPostBack="true" OnSelectedIndexChanged="Search_SelectedIndexChanged" Height="22px" Width="130px">
<asp:ListItem Value="0">SELECT</asp:ListItem>
<asp:ListItem Text="Country" />
<asp:ListItem Text="Course" />
<asp:ListItem Text="University" />
<asp:ListItem Text="Batch" />
<asp:ListItem Text="Intake" />
<asp:ListItem Text="Year" />
<asp:ListItem Text="StudentGender" />
<asp:ListItem Text="Ethnicity" />
</asp:DropDownList>
<asp:SqlDataSource ID="sqlDataSourceKeyWord" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" > </asp:SqlDataSource>
<asp:DropDownList ID="ddlKeyWord" DataSourceID="sqlDataSourceKeyWord" AppendDataBoundItems="true" runat="server" Font-Strikeout="False" Height="23" Width="200px"></asp:DropDownList>
<%-- <asp:TextBox ID="txtSearch" runat="server" Width="200px"></asp:TextBox>--%>
<td> <asp:Button ID="btnsearch" runat="server" Text="Search" align="right" Width="80px" OnClick="btnSearch_Click" />
</td>
</div>
</td>
</tr>
</table>
<br />
<asp:SqlDataSource ID="SqlDataSourceStudent" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommandType="Text" FilterExpression="ScholarshipID = '{0}' OR CountryID = '{1}' " >
<FilterParameters>
<asp:ControlParameter ControlID="ddlScholarship" Name="ddlScholarship" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="ddlSearch" Name="ddlSearch" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="ddlKeyWord" Name="ddlKeyWord" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
This is code in .cs
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Name = ((Label)e.Row.FindControl("lblstdname")).Text;
string StudentID = ((Label)e.Row.FindControl("lblStudentID")).Text;
//e.Row.Cells[1].Text = Name;
//HyperLink h = new HyperLink();
//h.Text = e.Row.Cells[1].Text;
//Click at student name
//h.NavigateUrl = "informationEdit.aspx?StudentID=" + StudentID;
//e.Row.Cells[1].Controls.Add(h);
}
}
protected void Search_SelectedIndexChanged(object sender, EventArgs e)
{
ddlKeyWord.Items.Clear();
ddlKeyWord.Items.Insert(0, new ListItem("SELECT ", ""));
if (ddlSearch.SelectedItem.Text == "Country") //Country
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Country ORDER BY Country ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Country";
ddlKeyWord.DataValueField = "CountryID";
}
else if (ddlSearch.SelectedItem.Text == "Course") //Course
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Course ORDER BY CourseDescription ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "CourseDescription";
ddlKeyWord.DataValueField = "CourseID";
}
else if (ddlSearch.SelectedItem.Text == "University") //University
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Institution ORDER BY Institution ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Institution";
ddlKeyWord.DataValueField = "InstitutionID";
}
else if (ddlSearch.SelectedItem.Text == "Batch") //Bactch
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Batch ORDER BY Batch ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Batch";
ddlKeyWord.DataValueField = "BatchID";
}
else if (ddlSearch.SelectedItem.Text == "Intake") //Intake
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Intake ORDER BY Intake ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Intake";
ddlKeyWord.DataValueField = "IntakeID";
}
else if (ddlSearch.SelectedItem.Text == "Year") //Graduate Year
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Year ORDER BY Year ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Year";
ddlKeyWord.DataValueField = "YearID";
}
else if (ddlSearch.SelectedItem.Text == "StudentGender") //Gender
{
DataTable table = new DataTable();
table.Columns.Add("Gender", typeof(string));
table.Rows.Add("Female");
table.Rows.Add("Male");
ddlKeyWord.DataSourceID = null;
ddlKeyWord.DataSource = table;
ddlKeyWord.DataTextField = "Gender";
ddlKeyWord.DataValueField = "Gender";
ddlKeyWord.DataBind();
}
else if (ddlSearch.SelectedItem.Text == "Ethnicity") //Ethnicity
{
sqlDataSourceKeyWord.SelectCommand = "SELECT * FROM Ethnicity ORDER BY Ethnicity ASC";
ddlKeyWord.DataSourceID = "sqlDataSourceKeyWord";
ddlKeyWord.DataTextField = "Ethnicity";
ddlKeyWord.DataValueField = "EthnicityID";
}
}
I have a problem where I dont know how to do the filter expression. Based on the code above I have 3 control parameter
1.ddlScholarship
2.ddlSearch
3.ddlKeyword
For Scholarship I can just do it like this Sholarship = '{0}' but for the other control parameter, I dont know how to do it. Since the dropdownlist for ddlKeyword will change based on the dropdownlist in ddlSearch.
I hope you guys understand what my problem is. Kindly respond me back if you have dont understand my problem. Thank you.