views:

43

answers:

1

Hi guys,

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.

A: 

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>
M4N
iiiiiiiyeah M4N :) What I was asking was if how to programatically create a SessionParamater. revising the question.
Nullstr1ng