Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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 Programatically in SqlDataSource?

UPDATE:
ok. I got it working now.

share|improve this question

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>
share|improve this answer
    
iiiiiiiyeah M4N :) What I was asking was if how to programatically create a SessionParamater. revising the question. – jaysonragasa Sep 6 '10 at 22:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.