Click here to Skip to main content
12,698,688 members (29,099 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
//i want this code should be run so that i will get values in dropdownlist which is listbox control //the values are available in database but how i will fetch in this dropdownlist which i have taken //in listbox

protected void gvUserInfo_ItemDataBound(object sender, ListViewItemEventArgs e)
      if (e.Item.ItemType == DataControlRowType.DataRow)//error
            DropDownList ddl = (DropDownList)e.Item.FindControl("ddsponcor");
           SqlCommand cmd = new SqlCommand("select sponcorid from Registration_Master", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ddl.DataSource = ds;
            ddl.DataTextField = "sponcorid";
            ddl.DataValueField = "sponcorid";
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));

//Operator '==' cannot be applied to operands of type //'System.Web.UI.WebControls.ListViewItemType' and //'System.Web.UI.WebControls.DataControlRowType'

//so what should i use instead.. to execute my code. please help me...
Posted 2-Dec-12 4:31am
Updated 2-Dec-12 4:32am
Krunal Rohit 2-Dec-12 9:49am
So you want ListBox items in DropDownList ??
aspnet_regiis -i 2-Dec-12 13:07pm
nice catch.. copy paste does not work always..
Krunal Rohit 2-Dec-12 23:28pm
I didn't get you..
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

control you are using should be datagrid and use following code to compare rows
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))

sumit kausalye 3-Dec-12 11:29am
Control is ListView
ManojDhobale 4-Dec-12 0:09am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

foreach (ListItem li in ListBox1.Items)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I cant be sure but in VB we use TYPEOF
so your IF statement would be written as......

 if (TypeOf(e.Item) == DataControlRowType.DataRow)

It may not work (as i dont know c#) but theres a chance it may.
sumit kausalye 3-Dec-12 1:43am
no it is not working
Zaf Khan 3-Dec-12 5:08am
The reason its not working is because yur trying to make an object type comparision the difference being your comparing a DATAROW to a LISTITEMEVNTARG to see if they are the same type, which obviously they're not.

And to clarify with you...
What your saying is that you have a drop down list and a listbox.
The dropdownlist is popultaed from the Database and you wish to populate the list from the dropdownlist, a type of filtering so-to-speak.

I dont think you need to COMPARE the "e as ListViewEventArgs" to a DATAROW, but to simply check that the parameter "e asLIstViewEventArgs") exists.

As Im not sure of C coding i canot tell you how
but if i was doing it in VB then i would write...
If ((e is nothing) = False) Then

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100