locked
SelectParameter in SelectCommand does not always has a valid value RRS feed

  • Question

  • User206383436 posted

    I have a datasource control with a SELECT statement and SelectParameters as follows:

    <cc1:PgSqlDataSource 
            ID="dsdocDetalle" 
            runat="server" 
            OldValuesParameterFormatString="Original_{0}" 
            ProviderName="<%$ ConnectionStrings:PgSqlConnection.ProviderName %>" 
            SelectCommand="SELECT 
    det_id, det_id_doc, det_tipo_docto, det_cliente, det_archivo_pdf, 
    tdc_nombre, cte_nombre
    FROM 
    documentos_detalle 
    INNER JOIN cat_tipos_docto ON tdc_id = det_tipo_docto 
    INNER JOIN cat_clientes ON cte_id = det_cliente 
    WHERE 
    det_id_doc = :prmDocId">
            <SelectParameters>
                <asp:SessionParameter SessionField="sesDocId" Type="Int32" Name="prmDocId" />
            </SelectParameters>
        </cc1:PgSqlDataSource>

    It is actually working fine but I would like to include 1 additional SelectParameter based on 1 control. I know that I must add a line like:

    <asp:ControlParameter ControlID="cboControl" PropertyName="Value" Name="ControlName" />

    My issue is that this control does not have a value because the user has the choice of selecting a value or not. It is a ComboBox and the user can decide to leave it blank. In this case, the SelectedIndex property would be -1 and it should no be considered as part of the condition. One solution is to write this code in C# but I want to know is there is a workaround so I can continue using the SELECT command and its parameters in the DataSource control.

    I will very much appreciate your feedback.

    Respectfully,
    Jorge Maldonado

    Sunday, June 26, 2016 5:53 PM

Answers