Click here to Skip to main content
15,885,952 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i bound the textboxes in first row now how to search the records in corresponding columns

What I have tried:

protected void grdColdStorageDetails_DataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
for (int i = 0; i < grdColdStorageDetails.Columns.Count; i++)
{
TableHeaderCell cell = new TableHeaderCell();
TextBox txtSearch = new TextBox();
txtSearch.Attributes["placeholder"] = grdColdStorageDetails.Columns[i].HeaderText;
txtSearch.CssClass = "search_textbox";
cell.Controls.Add(txtSearch);
row.Controls.Add(cell);
}
grdColdStorageDetails.HeaderRow.Parent.Controls.AddAt(1, row);
}
Posted
Updated 19-Mar-18 15:49pm

Things will get more complicated if you try to combine server-side controls with client-side functionality. GridView is a server-side data control which provides server-side capabilities that you can take advantage of. If you want manipulate the data in GridView at the client (JavaScript) then you'll have to learn JavaScript to manipulate the DOM (HTML elements). You could try looking at jQuery lib as it provides selectors that you can use to manipulate the DOM. But be aware that this may take you alot of time and effort if you are not familiar with client-side scripting.

You other option would be to use a pre-cooked client-side grid that does all the basic things you need for your grid. One good example is using Bootstrap DataTables. See this for demo: DataTables example - Individual column searching (text inputs)[^]
 
Share this answer
 
try this this my sample code... you have to change it
void bindsearch()
       {
           if (txtcname.Text == "" && txtdname.Text == "" && ddlicense.SelectedItem.Text == "All" && ddStatus.SelectedItem.Text == "All")
           {
               bind();
               return;
           }
           string str = "";

           if (txtcname.Text.Trim() != "")
           {
               str = "and ClientMst.ClientName like '%" + txtcname.Text.Trim() + "%'";
           }
           if (txtdname.Text.Trim() != "")
           {
               str = "and ClientMst.DisplayName like '%" + txtdname.Text.Trim() + "%'";
           }
           if (txtcname.Text.Trim() != "" && txtdname.Text.Trim() != "")
           {
               str = "and ClientMst.ClientName = '" + txtcname.Text.Trim() + "'";
           }
           if (ddStatus.SelectedItem.Text.Trim() != "All")
           {
               str = str + "and Active ='" + ddStatus.SelectedValue.Trim() + "'";
           }
           if (ddlicense.SelectedItem.Text.Trim() != "All")
           {
               str = str + "and License ='" + ddlicense.SelectedValue.Trim() + "'";
           }
           princ.Columns[1].Visible = true;
           string query = "  select ClientID,ClientName,DisplayName,ContPerson,contmob,case when License=1 then 'Full' else (Replace(convert(Varchar(20),Period,113),' ','/')) end as License, " +
                          "  Period,case when Active=0 then 'Yes' else 'No' end as Active " +
                          "  from ClientMst where ClientID<>'' " + str + " ";
           SqlCommand cmd = new SqlCommand(query, con);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           if (dt.Rows.Count != 0)
           {
               princ.DataSource = dt;
               princ.DataBind();
           }
           else
           {
               ddStatus.ClearSelection();
               ddlicense.ClearSelection();
               txtcname.Text = "";
               txtdname.Text = "";
               bind();
               MessageInfo.MessageIcon = MessageIcons.ErrorIcon;
               TMessageBox1.Show(this.Title, "NO Record", (TMessageBox.MessageIcons)MessageInfo.MessageIcon, true);
               return;
           }
           princ.Columns[1].Visible = false;
       }
 
Share this answer
 
Comments

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