Click here to Skip to main content
15,902,750 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.
Posted
Comments
ZurdoDev 14-Jan-14 10:46am    
There are many articles on this site as well as examples online. Where are you stuck?
Karthik_Mahalingam 15-Jan-14 0:58am    
what you want to display in the dropdownlist ?

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. :)
 
Share this answer
 
 
Share this answer
 
v2
Try like this..


XML
<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>




C#
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; }
       }




   }
 
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