我想在gridivew中添加列表框和下拉列表

我想在gridivew中添加列表框和下拉列表

本文介绍了我想在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.

推荐答案



<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中添加列表框和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:58