using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using
Utilities;
namespace GridViews
{
public partial class GridViewExample2 : System.Web.UI.Page
{
DBConnect objDB = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String strSQL = "SELECT * FROM Product";
gvProducts.DataSource
= objDB.GetDataSet(strSQL);
gvProducts.DataBind();
}
}
protected void btnOrder_Click(object sender, EventArgs e)
{
ArrayList arrProducts = new ArrayList(); // used
to store the ProductNumber for each selected product
int count = 0; // used to count the number of selected products
// Iterate through the rows (records) of the GridView and store the ProductNumber
// for
each row that is checked
for (int
row = 0; row < gvProducts.Rows.Count; row++)
{
CheckBox CBox;
//
Get the reference for the chkSelect control in the
current row
CBox
= (CheckBox)gvProducts.Rows[row].FindControl("chkSelect");
if (CBox.Checked)
{
String productId
= "";
// Get the ProductNumber from
the BoundField from the GridView
for the current row
//
and store the value in the array of selected products.
productId = gvProducts.Rows[row].Cells[1].Text;
arrProducts.Add(productId);
count
= count + 1;
}
}
//
Display the selected products
String str = "";
str = "You selected
" + count + "
products: <br/>";
foreach (String id in arrProducts)
{
str = str + id + "<br />";
}
lblDisplay.Text
= str;
}
} // end class
} // end namespace