public partial class WebForm4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!(IsPostBack)) { Session["List"] = null ; } } public static DataTable dt; public static int i = 1; // static int i = 1; //static List<string> lst; protected void btnAdd_Click(object sender, EventArgs e) { Session["List"] = dt; dt = new DataTable(); DataRow dr = null; // dt.Columns.Add(new DataColumn("RowNumber", typeof(int))); dt.Columns.Add(new DataColumn("Column1", typeof(string))); // dt.Columns.Add(new DataColumn("Column2", typeof(string))); if (Session["List"] == null) { dr = dt.NewRow(); dr["Column1"] = txtAdd.Text; dt.Rows.Add(dr); // lst.Add(txtAdd.Text); } else if (Session["List"] != null) { dt = (DataTable)Session["List"]; dr = dt.NewRow(); dr["Column1"] = txtAdd.Text; dt.Rows.Add(dr); //lst = (List<string>)Session["List"]; //lst.Insert(i,txtAdd.Text); //i++; } } protected void btnNew_Click(object sender, EventArgs e) { List<string> lst = new List<string>(); foreach (DataRow row in dt.Rows) { foreach (DataColumn col in dt.Columns) { lst.Add(row[col].ToString()); } } for (int j = 0; j >= dt.Rows.Count; j++) { } bool isfound = lst.Contains(txtSearch.Text); Response.Write(Convert.ToString(isfound)); dlshow.DataSource = dt; dlshow.DataBind(); } }
DataTable dtNew = dt.Clone(); //My Mistake...the "%" Should come after the single qoute.... DataRow[] dr = dt.Select("Column1 like '%" + txtSearch.Text.Trim() +"%'"); foreach(DataRow d in dr) { dtNew.ImportRow(d); } dlshow.DataSource =dtNew; dlShow.DataBind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)