0

I have a StoredProcedure called "usp_posts_getall" and it has 1 parameter called "@thisCategoryID"

in my "thisCategoryID", any values other than 0(zero) will return all the records in my Posts table.

Now I have a category menu items and each time I select, I set the value in my Session name called "SelectedCID".

So, How do I ... Create a SessionParameter Programmatically in SqlDataSource?


UPDATE:
ok. I got it working now.

1 Answer 1

1

If it's a session parameter that's used by the SqlDataSource, then you can set the value in the session, e.g in Page_Load():

Session["thisCategoryID"] = theCategoryId;

(am I misunderstanding the question?)

Ok, update:

I think you can create an event handler for the SqlDataSource.OnSelecting event. In that handler, you can access the Parameters collection of the datasource and can add another Parameter to it. I currently cannot test the following code, so it might not be fully correct, but I hope you see the idea:

SqlDataSource1_OnSelecting(SqlDataSourceSelectingEventArgs args)
{
  var param = new Parameter("@thisCatagoryID");
  param.DefaultValue = Session["SelectedCID"]; 
  SqlDataSource1.SelectParameters.Add(param);  
}

Alternatively, you can set the parameter declaratively in the markup, e.g:

<asp:SqlDataSource ...>
  <SelectParameters>
    <asp:SessionParameter Name="thisCategoryID" SessionField="SelectedCID"
      DefaultValue="0" />
    ...
  </SelectParameters>
</asp:SqlDataSource>
1
  • iiiiiiiyeah M4N :) What I was asking was if how to programatically create a SessionParamater. revising the question. Commented Sep 6, 2010 at 22:21

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.