How to add search option in GridView control in ASP.NET ?
How to add search option in GriView control in ASP.NET
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
How to add search option in GridView control in ASP.NET ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Shalini JunejaRank #351 · 7.1K reputationPosted Apr 12, 2011, 3:38 AM EDT
asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString ="$ ConnectionStrings:ConnectionString" %>"/> 2.Then add textbox and button on page: asp:textbox id="textbox1" runat="server"/> br/> asp:button id="button1" runat="server" text="search"/> 3.Then add select command to sqldatasource programatically from either code behind or runat="server"> Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click sqldatasource1.selectcommand = "select * from yourtable where modelfamily like '%" & textbox1.text & "%' or description like '%" & textbox1.text & "%'" sqldatasource1.databind() End Sub This will return rows that has column modelfamily or description with word in textbox1.text with wildcard in front and back - for example, if search keywork is "sam" -> it will return "samuel" as well. If textbox is blank, then ALL record is returned. Hope this helps you.