Click here to Skip to main content
15,898,826 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public DataSet fill_combo(DropDownList ddl, string field, string tbl, string condition)
{
    SqlDataReader dr = default(SqlDataReader);
    string[] a = null;
    ddl.Items.Clear();
    ListItem l = new ListItem();
    l.Text = "select";
    l.Value = (0);
    ddl.Items.Add(l);
    dr = viewrecord_dr(field, tbl, condition);
    if (field.Contains(","))
    {
        a = field.Split(',');
        while (dr.Read()) 
        {
            ListItem li = new ListItem();
            li.Value = dr.Item(0);
            li.Text = dr.Item(1);
            ddl.Items.Add(li);
        }
    }
    else
    {
        while (dr.Read())
        {
            ddl.Items.Add(dr.Item(0));
        }
    }
    dr.Close();
}
Posted
Updated 6-Jun-13 21:16pm
v2
Comments
_Amy 7-Jun-13 3:18am    
Which error? Where?
Raja Sekhar S 7-Jun-13 4:18am    
Are You Passing The Parameters Correctly...?
CHill60 7-Jun-13 5:50am    
Use the Improve question link to give us the details of the syntax errors you are getting

1 solution

dr is an SqlDataReader[^], right?
Its Item[^] property is indexed. Indexes in C# are given in square brackets like here
C#
li.Value = dr.Item[0];
For the other part, I can only guess that l is of type System.Web.UI.Controls.ListItem[^]. Its Value[^] property is of type System.String[^], just as the other property you set. Therefore you cannot assign a zero to it (the parentheses do exactly nothing here). Use
C#
l.Value = "0";
instead. Or, if the zero represents a variable, use that variable's ToString[^] overload.
 
Share this answer
 
v2

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