0
public void BindBatches()
{
    DataTable dtgetbatches = new DataTable();
    divBatches.Controls.Clear();
    dtgetbatches = breederdailybal.GetBreederBatches();
    if (dtgetbatches.Rows.Count > 0)
    {

        for (int i = 0; i < dtgetbatches.Rows.Count; i++)
        {
            Button btnbatch = new Button();
            btnbatch.ID = dtgetbatches.Rows[i]["batch"].ToString();

            btnbatch.Width = 90;
            btnbatch.ForeColor = Color.White;
            btnbatch.BackColor = Color.Green;
            btnbatch.Click += new EventHandler(btnbatch_Click);

            divBatches.Controls.Add(btnbatch);
            LiteralControl @break1 = default(LiteralControl);
            @break1 = new LiteralControl("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");
            divBatches.Controls.Add(@break1);
       }
    }
}

我想显示基于 dtgetbatches 对象的按钮。它不会生成正常的按钮是什么问题,请帮助我...

4

1 回答 1

0
   public void BindBatches()
   {
    DataTable dtgetbatches = new DataTable();
    divBatches.Controls.Clear();
    dtgetbatches = breederdailybal.GetBreederBatches();
    if (dtgetbatches.Rows.Count > 0)
    {

        for (int i = 0; i < dtgetbatches.Rows.Count; i++)
        {
            Button btnbatch = new Button();
            btnbatch.ID = dtgetbatches.Rows[i]["batch"].ToString();
            btnbatch.Text = "Batch" + " " + dtgetbatches.Rows[i]["batch"].ToString();
            btnbatch.Width = 90;
            btnbatch.ForeColor = Color.White;
            btnbatch.BackColor = Color.Green;
            btnbatch.Click += new EventHandler(btnbatch_Click);

            divBatches.Controls.Add(btnbatch);
            LiteralControl @break1 = default(LiteralControl);
            @break1 = new LiteralControl("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");
            divBatches.Controls.Add(@break1);
       }
    }

}

您没有添加 btnbatch.text 属性...它是如何根据 dtgetbatches 读取数据的...所以请小心编写并添加此代码

于 2013-10-03T07:08:51.090 回答