c# - Asp:Label that determined by dropdownlistbox not working properly -
this working other day, not sure happened isn't , cant figure out. label give me 1 item out of around 20(give or take) distinct items. no matter select in drop down list, gives me same value on label.
html:
<td> <asp:dropdownlist id="ddlcompanycode" runat="server" cssclass="dropdown" autopostback="true" onselectedindexchanged="ddlcompanycode_selectedindexchanged" width="139px" datasourceid="companycodeds" datatextfield="companycode" datavaluefield="companycode"></asp:dropdownlist> <asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server" controltovalidate="ddlcompanycode" display="dynamic" errormessage="*please select drop down list item." forecolor="#cc0000" validationgroup="submit"></asp:requiredfieldvalidator> </td> <td> <asp:label id="lblsourcesyst" runat="server" cssclass="txtlabel" text="select company code" width="137px" ></asp:label> </td> <asp:sqldatasource id="companycodeds" runat="server" selectcommandtype="storedprocedure" connectionstring="<%$ connectionstrings:rptdatamartconnectionstring %>" selectcommand="[axmap].[selectcompanycode_glsourcecoa]"> </asp:sqldatasource>
c#:
protected void page_load(object sender, eventargs e) { if (!ispostback) { ddlcompanycode.items.add(new listitem("--please select--", "")); ddlcompanycode.appenddatabounditems = true; } } protected void ddlcompanycode_selectedindexchanged(object sender, eventargs e) { string connectionstring = configurationmanager.connectionstrings["rptdatamartconnectionstring"].connectionstring; string sqlstoredproc = "rptdatamart.axmap.selectcompanycode_glsourcecoa"; sqlconnection con = new sqlconnection(connectionstring); sqlcommand cmd = new sqlcommand(); cmd.parameters.addwithvalue("@companycode", ddlcompanycode.selecteditem.value); cmd.commandtype = commandtype.storedprocedure; cmd.commandtext = sqlstoredproc; cmd.connection = con; try { con.open(); sqldatareader datareader = cmd.executereader(); while (datareader.read()) { lblsourcesyst.text = datareader["sourcesystem"].tostring(); } } catch (exception ex) { lblstatus.text = ex.message; } }
and stored procedure im trying use...
alter procedure [axmap].[selectcompanycode_glsourcecoa] @companycode varchar(10) = null, @sourcesystem nvarchar(255) = null begin set nocount off; select distinct companycode, sourcesystem [rptdatamart].[axmap].[glsourcecoa] end
my sql might terribly off, think work.
lblsourcesyst.text = datareader["sourcesystem"].tostring();
should be:
lblsourcesyst.text += datareader["sourcesystem"].tostring();
Comments
Post a Comment