Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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();
        }
    }
i have two textboxes one to add and other is to search i want to bind only those matching values matches with search textbox ( Like ' Like ' clause ) i am not using any data base
Posted
Updated 11-Mar-14 20:54pm
v2

C#
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();


Hope this Helps!!
 
Share this answer
 
v2
Comments
Member 10589943 12-Mar-14 3:07am    
DataRow[] dr = dt.Select("Column1 like '%" + txtSearch.Text + "%'");
thanks for sol.
Dinesh.V.Kumar 12-Mar-14 3:20am    
You are Welcome!!!
Dinesh.V.Kumar 12-Mar-14 3:20am    
If possible please vote for the solution..

Regards
Dinesh.V.Kumar 12-Mar-14 3:23am    
Thanks for the vote!!! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900