Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1035
Best event to set parameters for database query call
posted

What webhierachicaldatagrid or datasource event is considered to be the appropriate place to set select parameters for a database call?

I can set the parameters in the WebHierarchicalDataGrid DataBinding event, but only through the use of each parameters default value property!

Private Sub whdgPackages_DataBinding(sender As Object, e As EventArgs) Handles whdgPackages.DataBinding
    dsMatrix.SelectParameters("Type").DefaultValue = 1
    dsMatrix.SelectParameters("Tier").DefaultValue = CInt(ViewState("TIER"))
    dsMatrix.SelectParameters("Key").DefaultValue = CInt(ViewState("KEY"))
End Sub


Following is the underlying datasource Selecting event for a WebHierarchicalDataGrid. This seems to be getting called multiple times on a postback!!! Not sure if this is the proper place to do this.

Protected Sub dsMatrix_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles dsMatrix.Selecting
   e.Command.Parameters(0).Value = 1
   e.Command.Parameters(1).Value = CInt(ViewState("TIER"))
   e.Command.Parameters(2).Value = CInt(ViewState("KEY"))
End Sub

Parents
No Data
Reply
  • 20255
    Offline posted

    Hello,

    Thank you for using our forum!

    My suggestion is to set the parameters into the event handler for your datasource, OnSelecting event.

    Something like:

    <asp:SqlDataSource ... OnSelecting="ds_Selecting">

    ..
    protected void ds_Selecting(object sender, SqlDataSourceCommandEventArgs e)
    {
     e.Command.Parameters[0].Value = "Value";
    }

    Let me know if I may be of further assistance.

Children