0

I need use dynamic 'variable' name in this code. Can you help me?

Like this "Html object id.ToString();"

    public static void ddl(string sorgu,object ad)
    {
        using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["vtbag"].ConnectionString))
        {
            cnn.Open();
            using (SqlCommand cmd = new SqlCommand(sorgu, cnn))
            {
                using(SqlDataAdapter bakadp = new SqlDataAdapter(sorgu, cnn))
                {
                    using (DataTable baktbl = new DataTable())
                    {// Here is my problem
                        bakadp.Fill(baktbl);
                        html object id.DataSource = baktbl;
                        html object id.DataTextField = "ad";
                        html object id.DataValueField = "id";
                        html object id.DataBind();
                    }// End
               }
           }
     }
  • can you be more specific about what part in your code needs to be dynamic? – thepanch May 03 '16 at 22:14
  • html object name.DataSource = baktbl; html object name.DataTextField = "ad"; varihtml object nameable.DataValueField = "id"; html object name.DataBind(); actually i have to write this i guess – Uğur Canbulat May 03 '16 at 22:17
  • what is "html object id"? A repeater? Or a list view or something? You should get a reference to it as the type that it is, and then you can set its DataSource, etc properties. At least, I think this is what you mean by "dynamic variable". – Jonathan May 03 '16 at 23:20
  • a dropdownlist i try write a method for get dropdownlist values in database but a dynamic method is need a dynamic dropdownlist name original code html object id = object ad but i hit the wall so come to you – Uğur Canbulat May 04 '16 at 01:04
  • what if you explain what are you trying to do, your code doesn't have the best practice and maybe there is another way to do what you are trying to achieve. – thepanch May 04 '16 at 14:36
  • thank you every one i found it Button example = (Button)sender; like this sorry i cant explain it , low in english – Uğur Canbulat May 16 '16 at 12:41

0 Answers0