如何在gridview中动态添加多行? [英] How to add multiple rows dynamically in gridview ?

查看:73
本文介绍了如何在gridview中动态添加多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我希望在从列表框中选择多个值时在gridview中动态显示多行。

例如:

在下拉列表中选择爱好时,我会在列表框中找到爱好列表。当用户选择多个爱好我应该进入网格



1爱好阅读

2爱好绘图

3爱好烹饪





请在网格视图中建议以上述格式显示动态数据的代码。



先谢谢。

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.

推荐答案

您好,请使用以下代码



这是简单,例如使用列表。



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







.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



根据下拉选择到数据集或数据表获取数据。然后用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....


这篇关于如何在gridview中动态添加多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆