Click here to Skip to main content
14,735,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I want to display multiple rows dynamically in gridview on selection of multiple values from listbox.
for eg:
On selection of hobbies in dropdown, I get a list of hobbies in list box. When user selects multiple hobbies I should get in grid

1 Hobbies Reading
2 Hobbies Drawing
3 Hobbies Cooking


Please suggest the code to display dynamic data in above format in gridview.

Thanks in advance.
Posted
Comments
Tejas Vaishnav 19-Oct-13 3:03am
   
create a data source data table or data set based on a list view selection and bind it to your gird view.

Hi,Use the below code

This is simple eg by using the list.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           List<string> namelist = new List<string>();
           if (DropDownList1.SelectedIndex == 0)
           {
               namelist.Add("Abi");
               namelist.Add("Anand");
               namelist.Add("Arun");

               GridView1.DataSource = namelist;
               GridView1.DataBind();
           }
           else
           {
               List<string> nameslist = new List<string>();
               nameslist.Add("Balu");
               nameslist.Add("Banu");
               nameslist.Add("Batman");
               GridView1.DataSource = nameslist;
               GridView1.DataBind();
           }
       }




.aspx

<asp:DropDownList ID="DropDownList1" runat="server"

       onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" >
   <asp:ListItem>
   a
   </asp:ListItem>
   <asp:ListItem>
   b
   </asp:ListItem>
   </asp:DropDownList>
   <asp:GridView ID="GridView1" runat="server">
   </asp:GridView>
   
Hello Dhanasri

Get the data on the basis of drop down selection in to dataset or data table .And then bind with gridview......



I think it helps u....
   

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