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());
sqlConn.Open();
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.DataBind();
ddl.Items.Insert(0, DefaultSelText);
ddl.Items.FindByText(DefaultSelText).Value = "0";
}
else
{
ddl.Items.Insert(0, DefaultSelText);
ddl.Items.FindByText(DefaultSelText).Value = "0";
}
sqlCmd.Dispose();
sqlRdr.Dispose();
sqlConn.Close();
}
}