How to dynamically bind asp.net repeater control to datasource

前端 未结 5 558
情话喂你
情话喂你 2021-01-21 06:22

I have a page with a simple dropdown and repeater control in page.on submit repeater control is bound to datasource1 which has 3 columns.

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 07:27

    You can simply use like this -

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
       using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RBConnectionString"].ConnectionString))
       {
          SqlCommand cmd = new SqlCommand("select * from Customers", con);
          cmd.CommandType = CommandType.StoredProcedure;
          SqlDataAdapter adpt = new SqlDataAdapter(cmd);
          DataTable dt = new DataTable();
          adpt.Fill(dt);
          repeaterObj.DataSource = dt;
          repeaterObj.DataBind();
          cmd.Dispose();
        }
     }
    

提交回复
热议问题