sql server - call connectionstring in sqldatasource -


how can call connection string in sqldatasource class instead of writing directly ?

    <asp:sqldatasource  id="sqldatasource" runat="server" connectionstring="..." selectcommand="sp"    selectcommandtype="storedprocedure">          </asp:sqldatasource> 

public class cxxx {       public string connectionstring() {             return "data source=.\sqlexpress;initial catalog=db;integrated security=true;multipleactiveresultsets=true;pooling=false;";          }  } 

declare object

protected cxxx _myobject; 

then, in page_load:

protected void page_load(object sender, eventargs e) {          _myobject = new cxxx(); } 

then, in default.aspx, can do:

<asp:sqldatasource  id="sqldatasource" runat="server" connectionstring="<%= cxxx .connectionstring() %>" selectcommand="sp"    selectcommandtype="storedprocedure"> </asp:sqldatasource> 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -