c# - 动态创建的按钮出现在页面底部
问题描述
我目前正在 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 个按钮 我在这里做错了什么?
解决方案
推荐阅读
- firebase - 从 Xamarin.iOS 文件修改 Xamarin.Forms 页面
- xcode - 命令 PhaseScriptExecution 失败,退出代码非零 - 没有这样的文件或目录
- django - Django找不到静态文件
- dialogflow-es - 一串随机数字正在调用 Dialogflow 操作
- excel - 从一行复制特定单元格并粘贴到另一张表中,在下一行重复并重复直到下一行中的单元格为空白
- java - CORS Origin 失败的 Spring Boot
- javascript - 如何使用文本创建 td 边框
- sql - SQL如何使用JOIN和GROUPBY显示一个MAX函数的匹配情况
- java - Spring Kafka、Spring Cloud Stream 和 Avro 兼容性未知的魔法字节
- postgresql - 将除法的其余部分放入下一行