Gridview server control – Databinds to enumerable collections of objects and renders in a tabular format.
Must call ToList() on DbSet to bind to a databound control.
gridControl.DataSource = dbCustomers.ToList(); gridControl.DataBind();
Implementing a Button Command in a GriedView
Click Chevron -> GridView Taks -> Edit Columns…
BoundField – Databind to a object property
ButtonField – Hyperlink Button
Handle button click in the GridView_RowCommand event handler.
protected void GriedView1_RowCommand(object sender, GridViewCommandEventArgs e){ //Retrieve the ROW CLICKED in the grid int index = Convert.ToInt32(e.CommandArgument); GridView1 row = GridView1.Rows[index] //Accessing the cells is risky because the order of the columns may change //over time and you might forget that this depends on it. Also ..... 0 based! var someValue = row.Cells[1].Text; }