首页 > 解决方案 > 动态创建的按钮出现在页面底部

问题描述

我目前正在 asp.net 中的网站/博客/商店上工作。我的商店有问题。在我成功将项目添加到购物篮并转到应该通过 GridView 显示项目的页面后,按钮列根本没有出现,按钮显示在页面底部。

我在 C# 中动态创建列和行

Grid() 函数在页面加载时调用。其他列和行字符串类型在 GridView 中正常工作。

我试过用谷歌搜索这个问题,但我什么也没找到。

    protected void Grid()
    {
        if (Korpetina.proizvodi.Count > 0) //Items that are in basket
        {

            DataTable dt = new DataTable();
            dt.Columns.Add("Naziv proizvoda", typeof(string));
            dt.Columns.Add("Komada", typeof(double));
            dt.Columns.Add("Ukloni", typeof(Button)); // this is button type column that isn't appearing, other work just fine
            dt.Columns.Add("Cena", typeof(string));
            for (int i = 0; i < Korpetina.proizvodi.Count; i++) //going through items in the basket
            {

                DataRow dr = dt.NewRow();//assiging values to the rows

                dr["Naziv proizvoda"] = Korpetina.proizvodi[i];
                dr["Komada"] = "1";

                Button b = new Button //creating buttons
                {
                    ID = i.ToString(),
                    Text = "Ukloni",

                    Height = 13,
                    Width = 30
                };
                b.Click += new EventHandler(Click);
                form1.Controls.Add(b); //adding to aspnet form control
                dr["Ukloni"] = b;      //assigning button to the button row        
                dr["Cena"] = Korpetina.cene[i];
                dt.Rows.Add(dr);

            }

            DataRow d = dt.NewRow();//adding another row for total price, also works just fine
            d["Cena"] = Korpetina.ukupno;
            dt.Rows.Add(d);
            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
    }

按钮类型列中gridview的每一行都应该有按钮。

这就是它的实际外观:http : //prntscr.com/otjs4b gridview 中 4 行的 4 个按钮 我在这里做错了什么?

标签: c#htmlasp.net-coreaspxgridview

解决方案


推荐阅读