I am currently working on website/blog/shop in asp.net. I have problems with shop. After I successfully add items to basket and go to page that is supposed to display items via GridView buttons column is not appearing at all and buttons are showing at the bottom of the page.
I dynamically created columns and rows in c#
Grid() function is called on page load. Other columns and rows string type are working properly in GridView.
I have tried googling this problem but I found nothing.
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();
}
}
There is supposed to be button in each row of the gridview in button type column.
This is how it actually looks : http://prntscr.com/otjs4b 4 buttons for 4 rows in gridview What am I doing wrong here?