Click here to Skip to main content
Rate this: bad
good
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
        {
            con.Open();
            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();
            da.Fill(ds);
            con.Close();
            ddl.DataSource = ds;
            ddl.DataTextField = "sponcorid";
            ddl.DataValueField = "sponcorid";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--Select--", "0"));
        }
    }
//Error
//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 3:31am
Edited 2-Dec-12 3:32am
v2
Comments
Krunal Rohit at 2-Dec-12 9:49am
   
So you want ListBox items in DropDownList ??
aspnet_regiis -i at 2-Dec-12 13:07pm
   
nice catch.. copy paste does not work always..
Krunal Rohit at 2-Dec-12 23:28pm
   
I didn't get you..
Rate this: bad
good
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))
{
 
}
  Permalink  
Comments
sumit kausalye at 3-Dec-12 11:29am
   
Control is ListView
ManojDhobale at 4-Dec-12 0:09am
   
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.aspx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

foreach (ListItem li in ListBox1.Items)
  {
      DropDownList1.Items.Add(li);
  }
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
sumit kausalye at 3-Dec-12 1:43am
   
no it is not working
Zaf Khan at 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...
<pre>
If ((e is nothing) = False) Then
</pre>

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

  Print Answers RSS
0 CPallini 375
1 Sergey Alexandrovich Kryukov 370
2 BillWoodruff 314
3 George Jonsson 279
4 OriginalGriff 257
0 OriginalGriff 5,030
1 CPallini 4,115
2 Sergey Alexandrovich Kryukov 3,554
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
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