using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using APNSoft.WebControls;

public partial class DataGrid_RowServerSelection : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Apply event-handling method
        myDataGrid.OnRowClick += new DataGridEventHandler(myDataGrid_SelectCommand);


        //Define SQL query
        string SqlQuery = @"SELECT CustomerID, CompanyName, ContactName, Address, PostalCode " + 
            "FROM Customers ORDER BY CustomerID";

        //Get DataTable (MS Access Database)
        DataTable myDataSource = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/Nwind.mdb");

        //Set the data source
        myDataGrid.KeyFieldName = "CustomerID";
        myDataGrid.DataSource = myDataSource;
        myDataGrid.DataBind();

    }


    //The Server Side Procedure
    private void myDataGrid_SelectCommand(object sender, DataGridEventArgs e)
    {
        //Get selected row
        GridRow myGridRow = e.GridRow;
        if (myGridRow == null) return;

        //Reset the lblSelRow
        lblSelRow.Text = "";
        lblSelRow.Text += "Row index: <b>" + myGridRow.RowIndex + "</b><br/>";

        for (int i = 0; i < myGridRow.Cells.Count; i++)
        {
            lblSelRow.Text += myGridRow.Cells[i].ColumnName + ": <b>" +
                myGridRow.Cells[i].Value.ToString() + "</b><br/>";
        }
        
        lblSelRow.Text += "<br/>";

    }

}