ViewState Value as Parameter for SQLDataSource

Discussion in 'ASP .Net' started by Dave, Dec 21, 2009.

  1. Dave

    Dave Guest

    Is it possible to use a ViewState Value as a Parameter for a
    SQLDataSource? Looking at the options available as a Parameter
    Source...it looks like no. But I'm being told that you can.

    Comments/instructions?

    Thanks
     
    Dave, Dec 21, 2009
    #1
    1. Advertising

  2. Dave

    brislic2

    Joined:
    Dec 21, 2009
    Messages:
    2
    Not directly but you could always do something like :
    Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
    e.Command.Parameters("whatever") = ViewState("whatever")

    End Sub

    Which is what it does in the background anyways
    You just leave it blank in the selection screen
     
    brislic2, Dec 21, 2009
    #2
    1. Advertising

  3. On Dec 21, 6:26 pm, Dave <> wrote:
    > Is it possible to use a ViewState Value as a Parameter for a
    > SQLDataSource?  Looking at the options available as a Parameter
    > Source...it looks like no.  But I'm being told that you can.
    >
    > Comments/instructions?
    >
    > Thanks


    Dave, you can do this from the code behind. For example, if you need
    on select - use SqlDataSource.Selecting Event

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.selecting.aspx

    Example:

    protected void SqlDataSource1_Selecting(object sender,
    SqlDataSourceSelectingEventArgs e)
    {
    e.Command.Parameters["@OrderID"].Value = ViewState["OrderID"];
    }
     
    Alexey Smirnov, Dec 22, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew
    Replies:
    3
    Views:
    2,900
    Andrew
    Apr 1, 2004
  2. K B
    Replies:
    2
    Views:
    3,758
    Kees de Winter
    Mar 30, 2006
  3. Ken Cox [Microsoft MVP]
    Replies:
    3
    Views:
    479
    Walter Wang [MSFT]
    Jun 20, 2007
  4. Abraham Luna

    asp.net 2.0 SqlDataSource control parameter default value

    Abraham Luna, Aug 19, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    163
    Abraham Luna
    Aug 19, 2005
  5. Abdul Mohsin
    Replies:
    1
    Views:
    277
Loading...

Share This Page