Try this. it works good :)
aspx page
<div>
<div style="padding:10px; width: 200px; height:500px; background-color:#2C956C; float: left">
<asp:label id="Label1" runat="server" text="Categories" font-bold="True" xmlns:asp="#unknown">
Font-Size="16pt" Font-Underline="True" ForeColor="White"></asp:label>
<br />
<asp:dropdownlist id="DropDownListCategories" runat="server" xmlns:asp="#unknown">
AutoPostBack="True" Height="30px"
onselectedindexchanged="DropDownListCategories_SelectedIndexChanged"
Width="100%">
</asp:dropdownlist>
</div>
<div style="width: 800px; height:499px; padding:10px; background-color: #BEAA6C; float: left">
<asp:gridview id="ProductOfCategory" runat="server" backcolor="White" xmlns:asp="#unknown">
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Horizontal">
<footerstyle backcolor="#CCCC99" forecolor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="White" forecolor="Black" horizontalalign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F7F7F7" />
<sortedascendingheaderstyle backcolor="#4B4B4B" />
<sorteddescendingcellstyle backcolor="#E5E5E5" />
<sorteddescendingheaderstyle backcolor="#242121" />
</asp:gridview>
</div>
</div>
CodeBehind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetCategories();
int ID = 0;
int.TryParse(Request.QueryString["categoryID"], out ID);
if (ID > 0)
{
GetProdutByCategory(ID);
}
}
}
private void GetProdutByCategory(int CategoryID)
{
SqlDataAdapter da = new SqlDataAdapter("Select ProductName,UnitPrice,UnitsInStock from Products Where CategoryID=@id", "Server=.;Database=NorthWind;uid=sa;pwd=1");
da.SelectCommand.Parameters.AddWithValue("@id", CategoryID);
DataTable dt = new DataTable();
da.Fill(dt);
ProductOfCategory.DataSource = dt;
ProductOfCategory.DataBind();
}
private void GetCategories()
{
SqlDataAdapter da = new SqlDataAdapter("Select * from Categories", "Server=.;Database=NorthWind;uid=sa;pwd=1");
DataTable dt = new DataTable();
da.Fill(dt);
DropDownListCategories.DataSource = dt;
DropDownListCategories.DataTextField = "CategoryName";
DropDownListCategories.DataValueField = "CategoryID";
DropDownListCategories.DataBind();
}
protected void DropDownListCategories_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownListCategories.SelectedIndex != -1)
{
Response.Redirect("WebForm2.aspx?categoryID=" + DropDownListCategories.SelectedValue);
}
}