asp.net - Repeater control search button -
my repeater control showing database fields on load.
i have search button outside repeater control. when button pressed, want repeater show only searched result in repeater. how can that?
this code showing all.on search don't want show below details inside repeater.just searched results.
protected sub bindrepeater() dim cmd new sqlcommand("select * abc", con)
if con.state = connectionstate.closed con.open() end if dim ds new dataset() dim adp new sqldataadapter(cmd) adp.fill(ds) ' repeater1.datasource = ds repeater1.databind() con.close()
end sub below new code have added in search button
cmd = new sqlcommand cmd.connection = con cmd.commandtext = "select * abc licenseid = '" & textbox16.text & "'" drd = cmd.executereader if drd.hasrows = true drd.read() end if using con = new sqlconnection("data source=abc-556012rt13\sqlexpress;initial catalog=kabc;integrated security=true") using da = new sqldataadapter("select * abc licenseid = @licenseid", con) da.selectcommand.parameters.addwithvalue("@licenseid", textbox16.text) dim table = new datatable da.fill(table) repeater1.datasource = table repeater1.databind() end using end using
use sql-parameters prevent sql-injection!
apart that, use result of query datasource of repeater, example filling datatable
:
using con = new sqlconnection("connectionstring") using da = new sqldataadapter("select * abc licenseid = @licenseid", con) da.selectcommand.parameters.addwithvalue("@licenseid", textbox16.text) dim table = new datatable da.fill(table) repeater1.datasource = table repeater1.databind() end using end using
i'm using using
-statement ensure unmanaged resources(like open connection) disposed on error.
Comments
Post a Comment