Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
please help

I have a dropdownlist and a gridview on my webpage.

Gridview must be displayed based on dropdownlist item selection....till that it should not display Gridview.

Only Gridview must be displayed when item selected from dropdownlist.

thanks in advance.
Posted
Comments
Vani Kulkarni 10-Apr-13 2:25am    
What is the issue? Where are you stuck? Please post the code.

XML
<asp:DropDownList ID="ddlView" runat="server"
        onselectedindexchanged="ddlView_SelectedIndexChanged" AutoPostBack="true">
        <asp:ListItem Value="Select" Text="Select.."></asp:ListItem>
    <asp:ListItem Value="FirstGrid" Text="First Grid"></asp:ListItem>
     <asp:ListItem Value="SecondGrid" Text="Second Grid"></asp:ListItem>
      <asp:ListItem Value="ThirdGrid" Text="Third Grid"></asp:ListItem>
    </asp:DropDownList>
   <asp:GridView ID="gvFirst" runat="server">
   </asp:GridView>
   <asp:GridView ID="gvSecond" runat="server">
   </asp:GridView>
   <asp:GridView ID="gvThird" runat="server"></asp:GridView>


Code Behind is
C#
protected void ddlView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlView.SelectedValue.ToString() == "Select")
            {
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();
            
            }
            else if (ddlView.SelectedValue.ToString() == "FirstGrid")
            {
                DataTable table = new DataTable();               
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("First Grid");
                gvFirst.DataSource = table;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();
                
            }
            else if (ddlView.SelectedValue.ToString() == "SecondGrid")
            {
                DataTable table = new DataTable();
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("Second Grid");
                gvSecond.DataSource = table;
                gvSecond.DataBind();
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvThird.DataSource = null;
                gvThird.DataBind();

            }
            else
            {
                DataTable table = new DataTable();
                table.Columns.Add("Selection", typeof(string));
                table.Rows.Add("Third Grid");
                gvThird.DataSource = table;
                gvThird.DataBind();
                gvFirst.DataSource = null;
                gvFirst.DataBind();
                gvSecond.DataSource = null;
                gvSecond.DataBind();

            }
        }
 
Share this answer
 
v2
Let me search this for you :-

Le me search for you[^]

Hope it will help you.
 
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