I have been unable to figure this problem out. I used a SqlDataReader to generate data from my database into a grid view. I have been trying to generate buttons on each row, which I want to use to update the database.
I have been unable to get any values from the table to attach to the buttons. I am hoping to bind the ID but nothing I try works.
Here is my code for the original data binding query:
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ID, Width, Length, DockID from Slip where ID not in (select slipID from lease) and dockID = @dockId", con);
cmd.Parameters.AddWithValue("@dockId", dockId);
SqlDataReader dr = cmd.ExecuteReader();
gridView.DataSource = dr;
gridView.DataBind();
con.Close();
}
This is my attempt to generate buttons on each column, which work but I am unable to get any values from the table to bind to the buttons.
foreach (TableRow row in gvAvailableLeaseSlips.Rows)
{
TableCell btnCell = new TableCell();
Button btn = new Button();
btn.Text = "Lease Slip";
btn.CssClass = "btn";
btn.Click += new EventHandler(BtnLease_Click);
btnCell.Controls.Add(btn);
row.Cells.Add(btnCell);
}