Click here to Skip to main content
16,018,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdown list and data grid..

dropdownlist is seleting categoryId value from the categories database table.

i want that as soon as the value is seleted from the dropdown list..
the griw view show the products beleng to that catagory.

but my problem is that when i select catagoryname in the dropdownlist it is seleted . but not updating the gridview on the bases of category name..

i think dropdown list is just selecting. not redircting to update grid view. here is the code. what changes i have to do to work it correctly.

C#
public partial class Admin_procat : System.Web.UI.Page
{
    dbcon obj = new dbcon();
    protected void Page_Load(object sender, EventArgs e)
    {
        //dbcon obj = new dbcon();
        if (!IsPostBack)
        {
            string querydr = "select * from ESK_Categories";
            SqlDataReader dr = obj.fillcomb(querydr);
            DropDownList1.DataSource = dr;
            DropDownList1.DataValueField = "CategoryName";
            DropDownList1.DataBind();

           // Response.Redirect("procat.aspx");
           
        }
        if (!IsPostBack)
        {
            bind();

        }

       
    }
    public void bind()
    {
        //string query = "select * from ESK_Products";
        string query = "SELECT * FROM ESK_Products LEFT JOIN ESK_Categories ON ESK_Categories.CategoryID=ESK_Products.CategoryID Where ESK_Categories.CategoryName='" + DropDownList1.Text + "'";  
        DataSet ds = obj.fillgrid(query);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Response.Redirect("procat.aspx");
    }
}
Posted

1 solution

Make sure dropdownlist AutoPostBack property set to true and the selected index changed event is firing.
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       // calling the bind method. 
       bind();
       //Response.Redirect("procat.aspx");
   
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900