only My site

Friday, November 23, 2012

Grid & DataTable Tips


The below is the sample to show a alert message in the ASP.Net Grid View

int intTotalColumns = grdGRIDName.Rows[0].Cells.Count;
grdGRIDName.Rows[0].Cells.Clear();
grdGRIDName.Rows[0].Cells.Add(new TableCell());
grdGRIDName.Rows[0].Cells[0].ColumnSpan = intTotalColumns;
grdGRIDName.Rows[0].Cells[0].Text = "No records are found!";
grdGRIDName.Rows[0].Cells[0].Style.Add("text-align", "Center");
grdGRIDName.Rows[0].Cells[0].Style.Add("color", "red");

The below is the sample to filter the Data in a DataTable using column name and value.

DataTable users = (DataTable)Session[DB_USERS];

var items = users.AsEnumerable().Where(p => p.Field<string>("FIELD_NAME").Contains(value));

No comments: