Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,

I have one dropdownlist in page. if i select any of one dropdown list , i need to populate values to inner grid control. so now how can i get inner grid id while dropdownlist selected index changed event.

Note: droplistlist box not in gridview. That is in separately.







Thanks in advance,

sundaramoorthy
Posted
Comments
DamithSL 26-Jun-12 4:12am    
update question with your code.
Sandeep Mewara 26-Jun-12 4:20am    
What do you mean by 'inner grid control' here?

Hi ,
Check this
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        using (
        SqlConnection con =
        new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
        {


            using (SqlCommand cmd = new SqlCommand("usp_test_all", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                adpt.Fill(dt);
                DropDownList1.DataSource = dt;
                DropDownList1.DataTextField = "OrderAmount";
                DropDownList1.DataValueField = "orderID";
                DropDownList1.DataBind();
            }
        }
    }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    using (
    SqlConnection con =
    new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
    {


        using (SqlCommand cmd = new SqlCommand("usp_test", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@id", DropDownList1.SelectedValue);
            DataTable dt = new DataTable();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}


XML
<div>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
</div>

Best Regards
M.Mitwalli
 
Share this answer
 
Simply write code for loading data in to GridView in SelectedIndexChanged event with parameters in Query. Ex.

C#
SqlConnection conString = new SqlConection(ConfigurationManager.ConnectionString["MyCon"].ConnectionString);
string Query = "SELECT * from exTable where Col1 = '"+ddlFlter1.SelectedItem.ToString()+"'";
SqlDataAdaptor adp = new SqlDataAdaptor(Query,ConString);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource= ds;
GridView1.DataBind();


Try this code and revert.
 
Share this answer
 

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