c# - using stored procedure in code behind to load infragistics grid -
i have infragistics grid auto generated columns how can assign strored proc result code behind
<ig:webscriptmanager id="webscriptmanager1" runat="server"></ig:webscriptmanager> <ig:webdatagrid id="entitygrid" runat="server" width="100%"> <behaviors> <ig:sorting> </ig:sorting> </behaviors> </ig:webdatagrid>
code behind
protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) { entityname.text = dropdownlist1.selecteditem.text; string @regardingobjectname = dropdownlist1.selecteditem.text.trim(); string strconnstring = configurationmanager.connectionstrings["liveleaseconnectionstring"].connectionstring; sqlconnection con = new sqlconnection(strconnstring); sqlcommand cmd = new sqlcommand(); cmd.commandtype = commandtype.storedprocedure; cmd.commandtext = "p_datalist_byregardingobject"; cmd.parameters.addwithvalue("@regardingobjectname", @regardingobjectname); cmd.connection = con; try { con.open(); entitygrid.datasource = cmd.executereader(); entitygrid.databind();
i need passin entity parameter stored proc. how can here?
i getting reader closed error
you need add controlparameter selectparameters
<asp:controlparameter name="entityid" controlid="dropdownlist1" propertyname="selecteditem" type="string" />
also see question how specify parameter value stored procedure in sqldatasource
edit can use selecting event shown here
writing sqldatasource in code behind in c# use code behind value
you can add select parameter
entitygrid.selectparameters.add("entityid", dropdownlist1.selecteditem.text);
just rename "entityid" name of parameter used sp
edit2 :
instead of
entitygrid.datasource = cmd.executereader(); entitygrid.databind();
try this
sqldatareader reader = cmd.executereader(); using (reader) { datatable table = new datatable(); table.load(reader); entitygrid.datasource = table; }
see link more :
http://mentaljetsam.wordpress.com/2008/11/20/loading-an-sqldatareader-into-a-datagridview/
Comments
Post a Comment