我想在gridivew中添加列表框和下拉列表 [英] i want to add listbox and dropdownlist in gridivew

查看:85
本文介绍了我想在gridivew中添加列表框和下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Listbox1如下





FacultyName



Ram

Suresh

Rajesh



Listbox2如下



课程费用



AFF

MFA

EFA





在gridview中我希望输出为Listbox1和Listbox2数据以gridvew显示,同时在listbox1中有多少Facultyname,其中很多Dropdownlist将在gridview中显示。





在gridview中我希望输出如下



FacultyName CourseIncharge 1



Ram AFF dropdownlist1

Suresh MFA dropdownlist2

Rajesh EFA dropdownlist3





我怎样才能在asp.ent中使用csharp。

Listbox1 as follows


FacultyName

Ram
Suresh
Rajesh

Listbox2 as follows

CourseIncharge

AFF
MFA
EFA


in gridview i want output as Listbox1 and Listbox2 data to be displayed in gridvew and simutaneously how much Facultyname is there in the listbox1 that much of Dropdownlist to be shown in gridview.


In gridview i want output as follows

FacultyName CourseIncharge 1

Ram AFF dropdownlist1
Suresh MFA dropdownlist2
Rajesh EFA dropdownlist3


for that how can i do in asp.ent using csharp.

推荐答案

创建一个新的 DataTable 并绑定数据()从那些 ListBoxes 获取数据。



你需要实现这个逻辑。自己尝试一下。如果您在编码时遇到任何特定问题,请回到此处并添加另一个解释问题的问题,以便我们提供帮助。



继续编码。 :)
Create a new DataTable and bind data (Columns and Rows) to that by taking data from those ListBoxes.

You need to implement this logic. Try something on your own. If you face any specific problem while coding, then come back here and add another question explaining the problem, so that we can help.

Keep coding. :)


请参阅以下链接:

在TemplateField的ItemTemplate中绑定DropDownList [ ^ ]

绑定下拉列表和列表框 [ ^ ]

将列表框值绑定到gridview [ ^ ]



这可能会有所帮助。
Refer below links:
Bind DropDownList in ItemTemplate of TemplateField[^]
Binding dropdownlist and listbox [^]
Bind the listbox values into gridview[^]

This may help.


试试这样..





Try like this..


<form id="form1" runat="server">
    <asp:ListBox ID="ListBox1" runat="server">
        <asp:ListItem Text="Ram" />
        <asp:ListItem Text="Suresh" />
        <asp:ListItem Text="Rajesh" />
    </asp:ListBox>
    <asp:ListBox ID="ListBox2" runat="server">
        <asp:ListItem Text="AFF" />
        <asp:ListItem Text="MFA" />
        <asp:ListItem Text="EFA" />
    </asp:ListBox>
    <asp:GridView ID="gridView" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="Name" DataField="Name" />
            <asp:BoundField HeaderText="Branch" DataField="Branch" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:DropDownList ID="ddl" DataSource='<%# Bind("ddlsoruce") %>'   runat="server">
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </form>













public partial class WebForm2 : System.Web.UI.Page
   {



       protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               List<Entity> lstSoruce = new List<Entity>();
               if (ListBox1.Items.Count == ListBox2.Items.Count)
               {
                   for (int i = 0; i < ListBox1.Items.Count; i++)
                   {
                       lstSoruce.Add(new Entity()
                       {
                           Name = ListBox1.Items[i].Text,
                           Branch = ListBox2.Items[i].Text,
                           ddlsoruce = ListBox1.Items.OfType<ListItem>().Select(k => k.Text).ToArray()
                       });


                   }
               }

               gridView.DataSource = lstSoruce;
               gridView.DataBind();



           }
       }

       class Entity
       {
           public string Name { get; set; }
           public string Branch { get; set; }
           public string[] ddlsoruce { get; set; }
       }




   }


这篇关于我想在gridivew中添加列表框和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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