Hi Vijayar,
I have created a table as University
create table university(UnivID int,UnivName varchar(90),UnivType varchar(90))
aspx code is as follows..
<asp:Label ID="Label1" runat="server" Text="Select University"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="fee" Value="fee"/>
<asp:ListItem Text="nonfee" Value="nonfee"/>
<asp:ListItem Text="full part time" Value="full_part_time" Selected="true"/>
</asp:DropDownList>
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
the codebehind to bind the gridview is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populategrid();
}
}
private void populategrid()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
SqlDataAdapter sda = new SqlDataAdapter("select * from university", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
//Label2.Text = DropDownList1.SelectedValue;
string filter = DropDownList1.SelectedValue;
SqlDataAdapter sda = new SqlDataAdapter("select * from university where UnivType='" + filter + "'", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
populategrid method is used here to fill the gridview from university table
on selectedindexchange em using the selected value as filter value to display only the required values into gridview..
I hope this helped u...
Thanks & Regards,
Vijayar, if this helps please login to Mark As Answer. | Alert Moderator