Piyush
Piyush

Reputation: 5325

how can i access string variable value of .aspx.cs file in .aspx file

i m getting a string value regression as regression = (Session["Regression"]).ToString(); in .aspx.cs file then i want to use this value in .aspx file in SelectCommand of SqlDataSource property as 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 is as 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();
     }

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

Upvotes: 1

Views: 3430

Answers (4)

user1509
user1509

Reputation: 1161

try this:

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

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

 <% =regression %>

Upvotes: 0

Ashwin Singh
Ashwin Singh

Reputation: 7375

Try this:

  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;
    }

Upvotes: 0

Mayank Pathak
Mayank Pathak

Reputation: 3681

You can you Session Variable's value 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 any other concerns on this..

Upvotes: 2

Waqar Janjua
Waqar Janjua

Reputation: 6123

add Session paramter to your sql Datasource 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>

Upvotes: 0

Related Questions