asp.net - Creating a Search Function, using stored procedure -


supposedly have projectcode textbox:

<td align="left" width="200px">   <asp:textbox id="tbprojectcode" runat="server" width="194px"></asp:textbox> </td> 

and 1 imagebutton:

<asp:imagebutton id="btnsearch" runat="server" imageurl="../support/image/magnifierglass.png" width="75%" height="75%" onclientclick="opennewwin();return false;" /> 

and gridview:

<asp:panel id="paneldgv" runat="server" height="100%" scrollbars="none" width="100%">   <asp:gridview id="dgv" runat="server" autogeneratecolumns="false" gridlines="none" allowpaging="true" pagesize="2" cssclass="mgrid" pagerstyle-cssclass="pgr" alternatingrowstyle-cssclass="alt">       <columns>   <asp:boundfield datafield="projectcode" headertext="project code" />   <asp:boundfield datafield="projectname" headertext="project name" />   <asp:buttonfield buttontype="image" imageurl="../support/image/edit.png" itemstyle-horizontalalign="center" commandname="cmdsearch" headertext="edit">   <itemstyle horizontalalign="center"></itemstyle>        </asp:buttonfield>           </columns>              <pagerstyle cssclass="pgr"></pagerstyle>                 <alternatingrowstyle cssclass="alt"></alternatingrowstyle>                     </asp:gridview>                        </asp:panel> 

and i"m using stored procedure query (i take value database, notice double dot in master..[ms_project]):

select [projectcode],[projectname]   master..[ms_project]   [projectcode] '%' + @projectcode + '%'   order [projectcode] asc 

i want create search function, user type textbox project code want, click imagebutton, search result should displayed in gridview, there anyway this? thank you.

edit

i add in .vb:

    protected sub btnsearch_click(byval sender object, byval e system.web.ui.imageclickeventargs) handles btnsearch.click     dim ds new dataset()      using connection new sqlconnection(configurationmanager.connectionstrings("cfgconnectionstring").tostring())         using command new sqlcommand()             command.commandtype = commandtype.storedprocedure             command.commandtext = "msproject_select"             command.connection = connection              command.parameters.addwithvalue("@projectcode", tbprojectcode.text)              connection.open()             dim new sqldataadapter(command)             a.fill(ds)         end using     end using      dgv2.datasource = ds     dgv2.databind() end sub 

end class

this can do:

protected void btnsearch_click(object sender, imageclickeventargs e)  {     dataset ds = new dataset();      using (sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["yourconnectionstring"].tostring()))         {             using (sqlcommand command = new sqlcommand())             {                 command.commandtype = commandtype.storedprocedure;                 command.commandtext = "youprocedurename";                 command.connection = connection;                  command.parameters.addwithvalue("@projectcode", tbprojectcode.text);                  connection.open();                 sqldataadapter = new sqldataadapter(command);                 a.fill(ds);              }         }      dgv.datasource = ds;     dgv.databind(); } 

the idea pretty simple. on search(click) event rebinding gridview new datasource retrieved new select query.

vb.net

protected sub btnsearch_click(sender object, e imageclickeventargs) dim ds new dataset()  using connection new sqlconnection(configurationmanager.connectionstrings("yourconnectionstring").tostring())     using command new sqlcommand()         command.commandtype = commandtype.storedprocedure         command.commandtext = "youprocedurename"         command.connection = connection          command.parameters.addwithvalue("@projectcode", tbprojectcode.text)          connection.open()         dim new sqldataadapter(command)         a.fill(ds)     end using end using  dgv.datasource = ds dgv.databind() end sub 

try vb code. have used conversion tool this. maybe might require modifications here.

following comment:

add line on page.

public string cfgconnectionstring = system.configuration.configurationmanager.connectionstrings("cfgconnectionstring‌​").connectionstring; 

and change first line this:

using connection new sqlconnection(configurationmanager.connectionstrings("cfgconnectionstring").tostring()) 

also missing

dim ds new dataset() 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -