Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir/Madam,

C#
protected void Page_Load(object sender, EventArgs e)    {
        cmd = new SqlCommand("Select ProductID, PName from tbl_Products", con);
        con.Open();
        DropDownList1.DataSource = cmd.ExecuteReader();
        DropDownList1.DataTextField = "PName";
        DropDownList1.DataValueField = "ProductID";
        DropDownList1.DataBind();
        
    }


And if i choose any one of the value from the above dropdownlist means ,

GridView wants to show the appropriate details...

My GridView as like below

ASP.NET
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                        DataKeyNames="ProductID">
                        <columns>
                            <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True" />
                            <asp:BoundField DataField="PName" HeaderText="Product Name" ReadOnly="True" />
                            <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" 
                                ReadOnly="True" />
                            <asp:BoundField DataField="Rate" HeaderText="Rate" ReadOnly="True" />
                        </columns>


My Question is how to display appropriate details in GridView when selecting the dropdownlist item(Suppose if i select "PName1" means regarding PName1 details such as ProductID, Manufacturer, Rate wants to show in the gridview)


C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView2.DataSource = ds;
        GridView2.DataBind();
        
    }
Posted
Updated 15-May-14 2:50am
v2
Comments
[no name] 15-May-14 7:49am    
"ds" has to come from somewhere first.

1 solution

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

SqlDataAdapter da = new SqlDataAdapter("Select columns from table where
[column]='" +ddl.SelectedValue + "'", connection);
dt = new DataTable();
da.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();
}
 
Share this answer
 
v3

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



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