c# - Accessing code behind method Variable in aspx page -
i working in custom detailed view. have program page views program. when user clicks on update button, user redirected manage programs page. manage programs page contains method fetches rows from.
public string programsdetails() { using (sqlconnection con = new sqlconnection(str)) { string htmlstr = ""; sqlcommand cmd = con.createcommand(); cmd.commandtext = " select * programs progid=@progid"; cmd.parameters.addwithvalue("@progid", "1"); con.open(); sqldatareader reader = cmd.executereader(); if (reader.read()) { int progid = reader.getint32(0); string progtitle = reader.getstring(1); string progbudget = reader.getstring(4); string progstardate = reader.getstring(5); } con.close(); return htmlstr; } }
how can access variable .aspx page? lets access progtitle
.
i have used method seems it's not working
<%=projtitle%>
i show values of each column in there respected text box
<div class="cmrs-panel-body no-padding"> <div class="cmrs-form-inline"> <div class="cmrs-form-row bordered"> <label class="cmrs-form-label">program code name</label> <div class="cmrs-form-item"> <input type="text" name="code" class="large"> </div> </div> </div> <div class="cmrs-form-inline"> <div class="cmrs-form-row bordered"> <label class="cmrs-form-label">program title</label> <div class="cmrs-form-item"> <input type="text" name="title" class="large" value="<%=progtitle %>"> </div> </div> </div> <div class="cmrs-form-inline"> <div class="cmrs-form-row bordered"> <label class="cmrs-form-label">program description</label> <div class="cmrs-form-item"> <textarea class="large"></textarea> </div> </div> </div> </div>
normally add html code method not feasible want variable value , display in textbox.
htmlstr+="<table><tr><td>"+progtitle+"</td></tr></table>";
progtitle
must declared protected
or public
in code behind make accessible .aspx. change code below
protected string progtitle; public string programsdetails() { using (sqlconnection con = new sqlconnection(str)) { string htmlstr = ""; sqlcommand cmd = con.createcommand(); cmd.commandtext = " select * programs progid=@progid"; cmd.parameters.addwithvalue("@progid", "1"); con.open(); sqldatareader reader = cmd.executereader(); if (reader.read()) { int progid = reader.getint32(0); progtitle = reader.getstring(1); string progbudget = reader.getstring(4); string progstardate = reader.getstring(5); } con.close(); return htmlstr; } }
then can access progtitle
in aspx code
<input type="text" name="title" class="large" value="<%=progtitle %>">
Comments
Post a Comment