1

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...

2
  • it can de done by using System.CodeDom,expressionBuilders, similar task i did it once satindersinght.blogspot.in/2012/01/… Commented Jul 12, 2012 at 5:47
  • This reminds me of why I hate WebForms. Commented Jul 12, 2012 at 5:51

4 Answers 4

2

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..

Sign up to request clarification or add additional context in comments.

Comments

0

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>

6 Comments

what error you are getting now ? This is the only way, you have to add the session feild to the sqldatasource declaratively ( in the aspx code ) or programatically ( in the code behind).
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%>'" actually the above command is not fetching the data from db because the query having incorrect value for column regression just for confirmation i m printing that value in one label at last on wep page but there it is printing as it is like <%#regression%>
no need to write regression in this format "<%=regression%>" bcz you have defined it in the select parameters. IF you specify the name Regresion in the session parameter inside the select parameters of sqldatasource then in your select command write the name of parameter which would be Regression. You query should look like 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'"
or go to design view of your webpage, select sqldatasource set it's database property and also set the session feild from there.
<asp:Label ID="regre" runat="server" Text=" name is regression" /> how can i print it on level for testing means it's coming in web page or not
|
0

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

1 Comment

not working.is there anything i have to do for <form id="form1" runat="server"> like get or set method????
0

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 %>

3 Comments

still not fetching the data from DB bcoz regression value is not coming from aspx.cs page to aspx page
check the 3rd post at this link: [link] (forums.asp.net/t/1115044.aspx/1) .. Hope it helps you
try the following search in google: "get string variable from code behind to sqldatasource" .. you'll get good results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.