Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview

Gridview

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahad Rahman
    wrote on last edited by
    #1

    retrive data from sql database to a gridview, then how to use search option in a gridview ?

    P L B 3 Replies Last reply
    0
    • R Rahad Rahman

      retrive data from sql database to a gridview, then how to use search option in a gridview ?

      P Offline
      P Offline
      prateekfgiet
      wrote on last edited by
      #2

      use this code it will help u private DataTable GetRecords() { conn.ConnectionString = "User ID=sa;Data Source=(local);Database=inventry"; //SqlConnection conn = new SqlConnection(strConnection); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = "Select ptype,pqty from total_stock"; SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; DataSet objDs = new DataSet(); dAdapter.Fill(objDs); return objDs.Tables[0]; } private void BindGrid() { DataTable dt = GetRecords(); if (dt.Rows.Count > 0) { grdSearch.DataSource = dt; grdSearch.DataBind(); } } private void SearchText() { DataTable dt = GetRecords(); DataView dv = new DataView(dt); string SearchExpression = null; if (!String.IsNullOrEmpty(txtSearch.Text)) { SearchExpression = string.Format("{0} '%{1}%'", grdSearch.SortExpression, txtSearch.Text); } dv.RowFilter = "ptype like" + SearchExpression; grdSearch.DataSource = dv; grdSearch.DataBind(); } public string Highlight(string InputTxt) { string Search_Str = txtSearch.Text.ToString(); // Setup the regular expression and add the Or operator. Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase); // Highlight keywords by calling the //delegate each time a keyword is found return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords)); // Set the RegExp to null. RegExp = null; } public string ReplaceKeyWords(Match m) { return "<span class=highlight>" + m.Value + "</span>"; } protected void txtSearch_TextChanged(object sender, EventArgs e) { SearchText(); }

      1 Reply Last reply
      0
      • R Rahad Rahman

        retrive data from sql database to a gridview, then how to use search option in a gridview ?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        DataTable dt = GetYourDataTable(); //Write code to get data from your database. DataView dv = new DataView(dt); dv.RowFilter = ""City = 'New York'"; //Write your filter condition GridView1.DataSource = dv; GridView1.DataBind();

        1 Reply Last reply
        0
        • R Rahad Rahman

          retrive data from sql database to a gridview, then how to use search option in a gridview ?

          B Offline
          B Offline
          Baran M
          wrote on last edited by
          #4

          Get something out of it

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups