How can I access the value of the string variable of the .aspx.cs file in the .aspx file

im gets the string value regression = (Session["Regression"]).ToString(); as regression = (Session["Regression"]).ToString(); in the .aspx.cs file, then I want to use this value in the .aspx file in the SelectCommand property of the SqlDataSource property, as shown below

 SelectCommand="SELECT [issue_oid], [issue_num], [regression], [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%#regression%>'"` 

.aspx.cs file page_load method as shown below

  protected void Page_Load(object sender, EventArgs e) { if ((Session["UserName"].ToString()) == string.Empty) { Server.Transfer("regressionType.aspx"); } regression = (Session["Regression"]).ToString(); usrname = (Session["UserName"]).ToString(); DataBind(); } 

suggest me how can i do this? thanks in advance...

+1
source share
4 answers

You can use the value of the Session variable in your SQLDatasource. Like this example.

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testDatabaseConnectionString %>" SelectCommand="SELECT * FROM [UserTable] WHERE ([userID] = @UserID)"> <SelectParameters> <asp:SessionParameter Name="UserID" SessionField="UserID" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> 

Let us know about other issues in this matter.

+2
source share

add the Session paramter parameter to your sql source like this

 <asp:SqlDataSource SelectCommand="SELECT [issue_oid], [issue_num], [regression], [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%#regression%>'"`> <SelectParameters> <asp:SessionParameter SessionField="Regression" Name="ParameterName" Type="String" /> </SelectParameters> </asp:SqlDataSource> 
0
source share

Try the following:

  SelectCommand="SELECT [issue_oid], [issue_num], [regression], [status], [tested_by], [tested_on], [patch_name], [arrived_on], [previous_info], [comment], [is_duplicate] FROM [itt_monthly_patch_issue_list] where status='Not Tested' and `regression='<%=ReturnRegression()%>'"` 

In codebehind:

  string regression=null;//Before Page_Load protected string ReturnRegression() { //Write logic here to prevent null being returned return regression; } 
0
source share

try the following:

 public StringBuilder regression = new StringBuilder(); regression.Append((Session["Regression"]).ToString()); 

Then on the .aspx page (in the selct command) you can use "regression" like:

  <% =regression %> 
0
source share

All Articles