i want to create a dynamic drop down list from a method that takes, primary key, value and table name; But I am unable to populate the dropdown.
I am a learner in asp.net so explain in simple terms with examples
here is my code…
front end
<asp:DropDownList id="UserPaidStatus" runat="server">
</asp:DropDownList>
backend method call
DropDownList UserPaidStatus = DataAutoPopulate.MakeNewDDL("cn_UserPaidStatus", "m_paidstatus", "m_id");
my method that is called
public static DropDownList MakeNewDDL(string tableName, string columnName, string primaryKeyColumn)
{
DropDownList ddl = new DropDownList();
// create connection to database
SqlConnection con = netCmsConnection.getDatabaseConnection();
String query = ("SELECT " + columnName + ", " + primaryKeyColumn + " FROM " + tableName);
SqlCommand command = new SqlCommand(query, con);
command.CommandType = CommandType.Text;
SqlDataAdapter adaptor = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adaptor.Fill(dt);
return ddl;
}
any ideas what i am doing wrong?