CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010

    dynamic drop down list

    I am pretty new to C# but from vb background

    i have about 20 dropdowns to be filled in a page and got about 12 diff pages in which i need to fill the same way.

    so just to cut short the code

    i created a class as below. this class is placed under the app_code and i am trying to call the below class from my code page as PropertyMax.fnFillDropdown(ddlArea, "spGetArea", "AreaId", "Area", "Select Area");

    it shows a red line and is not working. any help would be greatly appreciated.

    public class PropertyMax

    public static void fnFillDropdown(DropDownList ddl, string spName, string dbFieldId, string dbFieldName, string DefaultSelText)
    SqlConnection sqlConn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["PMDb"].ToString());

    SqlCommand sqlCmd = new SqlCommand(spName, sqlConn);
    sqlCmd.CommandType = CommandType.StoredProcedure;

    SqlDataReader sqlRdr;
    sqlRdr = sqlCmd.ExecuteReader();

    if (sqlRdr.HasRows)
    ddl.DataSource = sqlRdr;
    ddl.DataValueField = dbFieldId;
    ddl.DataTextField = dbFieldName;
    ddl.Items.Insert(0, DefaultSelText);
    ddl.Items.FindByText(DefaultSelText).Value = "0";
    ddl.Items.Insert(0, DefaultSelText);
    ddl.Items.FindByText(DefaultSelText).Value = "0";



  2. #2
    Join Date
    Jun 2008

    Re: dynamic drop down list

    How about telling us what error message you are receiving? "It's not working" doesn't help us at all.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width