We help IT Professionals succeed at work.

Change value of where parameter

Sheritlw
Sheritlw used Ask the Experts™
on
I have a gridview with a linqdatasource.
In the footer of the gridview I have a checkbox.  When a user clicks the checkbox, I need to set my where clause to active = false otherwise active = true.
I can get the checkbox in code behind so I will probably need to change it in the checkbox textchanged event.
How would I do this?

Thanks
<asp:LinqDataSource ID="lnqClientList" runat="server" 
        ContextTypeName="Service2020.SalonDataClassesDataContext" TableName="Clients" 
        Where="UserID == @UserID &amp;&amp; Active == @Active" 
      EnableDelete="True" OrderBy="FullName, LastServiceDate desc">
       <WhereParameters>
         <asp:SessionParameter DbType="Guid" Name="UserID" SessionField="UserID" />
          <asp:Parameter DefaultValue="true" Name="Active" Type="Boolean" />
      </WhereParameters>
   </asp:LinqDataSource>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
What if you used a ControlParameter instead?
<asp:ControlParameter Name="Active" ControlID="CheckBox1" DefaultValue="True" PropertyName="Checked" Type="Boolean" />

Open in new window

Commented:

I looked at and tried the checkbox solution, but neither provided the ability to dynamically change the where parameter.
I did finally figure it out and posted the code below.

I will split the points.

Thanks
<asp:LinqDataSource ID="lnqClientList" runat="server" 
        ContextTypeName="Service2020.SalonDataClassesDataContext" TableName="Clients" 
        Where="UserID == @UserID &amp;&amp; Active == @Active" 
      EnableDelete="True" OrderBy="FullName, LastServiceDate desc">
       <WhereParameters>
         <asp:SessionParameter DbType="Guid" Name="UserID" SessionField="UserID" />
          <asp:Parameter DefaultValue="true" Name="Active" 
             Type="Boolean" />
      </WhereParameters>
   </asp:LinqDataSource>

   Protected Sub chkShowInActive_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim chk As CheckBox = DirectCast(sender, CheckBox)
      If chk.Checked = True Then
         Me.lnqClientList.WhereParameters.Item("Active").DefaultValue = False
      Else
         Me.lnqClientList.WhereParameters.Item("Active").DefaultValue = True
      End If
      Me.grdClientList.DataBind()
      Me.UpdatePanelClientList.Update()
   End Sub

Open in new window

Author

Commented:
Figured out solution and posted it.