0

i have a webapplication in .net and use a DetailsView. im control this DetailsView with a SqlDataSource. i set a session with jquery.

     <script >
         var baseUrl = (window.location).href;
         var clubid = baseUrl.substring(baseUrl.lastIndexOf('=') + 1);
         sessionStorage.setItem("se", "13801");
         var ses = sessionStorage.getItem("se");
     </script>

Fields of DetailsView :

<Fields>
    <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
    <asp:BoundField DataField="name" HeaderText="name"
        SortExpression="name" />
    <asp:BoundField DataField="saltasis" HeaderText="saltasis" SortExpression="saltasis" />
    <asp:CommandField />
    <asp:CommandField ShowEditButton="True" />
    <asp:CommandField ShowInsertButton="True" />
    <asp:CommandField ShowDeleteButton="True" />
</Fields>

and SQLDATASOURCEID :

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sina1ConnectionString %>" 
    SelectCommand="SELECT * FROM [club] WHERE saltasis = @saltasis">
    <SelectParameters>
    <asp:SessionParameter Name="?" SessionField="?" Type="string" />
    </SelectParameters>

</asp:SqlDataSource>

how to use a session as a value in SelectCommand of SqlDataSource for DetailsView.

2 Answers 2

0

Store session value in hidden field with javascript. Pay attention, if you use the master page, the name of the hidden field is as follows:

document.getElementById('ContentPlaceHolder1_hiddenfield1').value = "session_value";

Then you can use the session value stored in the hidden field

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

Comments

0

Hi in your example I only show you save the session value inside your sessionStorage but you didn't past inside a html form or ajax as POST or GET. So you need to catch the url inside your controller: for example this URL (window.location).href https://domain.eg/ControllerName/ActionName?se=13801

[httpGet]
public void ActionName(string se)
{

  var sessionParams = se;
  -- do what you want with that...

}

2 Comments

How i usee this source as a select command?
To past you can do this Request.QueryString['se'] look at this stackoverflow.com/questions/13732975/…

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.