//2nd Column - No
BoundColumn colNo = new BoundColumn();
colNo.DataField = "NCMR_T_H_NO";
colNo.HeaderText = "No";
DGList.Columns.Add(colNo);
//3rd Column - Date
BoundColumn colDate = new BoundColumn();
colDate.DataField = "NCMR_T_H_DATE";
colDate.HeaderText = "Date";
colDate.DataFormatString = "{0:dd-MM-yyyy}";
DGList.Columns.Add(colDate);
//4th Column - Date
BoundColumn colStatus = new BoundColumn();
colStatus.DataField = "NCMR_T_H_STATUS";
colStatus.HeaderText = "Status";
DGList.Columns.Add(colStatus);
//5th Column - Created By
BoundColumn colBy = new BoundColumn();
colBy.DataField = "NCMR_T_H_BY";
colBy.HeaderText = "Created By";
DGList.Columns.Add(colBy);
}
Bind Data
private void Create_List()
{
string strSql;
//DataServer - a class where I put all the functions
DataServer ds = new DataServer();
//Create new DataTable
DataTable dt = new DataTable();
strSql = "SELECT * FROM TBL_NCMR_T_H WHERE ";
strSql = strSql + " NCMR_T_H_STATUS = 'Open'";
if (txtNCMR.Text != "")
{
strSql = strSql + " AND NCMR_T_H_NO = '" + ds.GetNCMR(Convert.ToInt16(txtNCMR.
Text)) + "'";
}
if (txtDate.Text != "")
{
strSql = strSql + " AND NCMR_T_H_DATE = #" + txtDate.Text + "#";
}
strSql = strSql + " ORDER BY NCMR_T_H_NO";
//List Data - function in DataServer that return DataTable
dt = ds.ListData(strSql);
DataView dv = new DataView(dt);
//DGList is the DataGrid name
DGList.DataSource = dv;
DGList.DataBind();
}
Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!(Page.IsPostBack))
{
Create_Column();
Create_List();