Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<asp:ControlParameter - pass null value to DB via sqldatasource

Tags:

tsql

asp.net

I'm having problems passing a null value to a stored procedure, e.g. if an option isn't selected on a dropdown how can this be passed as null to through the sqdatasource to the database.

I currently have a number of dropdown controls on my page which are holding paramater values to get passed to a stored procedure.

When I select some values from these controls the gridview will display the results that it should, but what I'm having a problem with is when no values are selected is passing a null value to the SP. I've checked the SP and when I execute it and pass in null values it gets me the correct results so I'm happy with the SP. I've tried

ConvertEmptyStringToNull="true" DefaultValue=""

settings in the control paramater with no luck, and the dropdown's "ALL" option has a value of ""

The code for the sqldatasource is:

                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:scConnString %>"
                    SelectCommand="spGetOrgTickets" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="false">
                    <SelectParameters>
                        <asp:SessionParameter Name="org_id" Type="Int32" SessionField="org_id" DefaultValue="" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter ControlID="drpPriority" Name="priority_id" PropertyName="SelectedValue"
                            Type="Int32" ConvertEmptyStringToNull="true" DefaultValue="" />
                        <asp:ControlParameter ControlID="drpStatus" Name="status_id" PropertyName="SelectedValue"
                            Type="Int32" ConvertEmptyStringToNull="true" DefaultValue=""/>
                    </SelectParameters>
                </asp:SqlDataSource>

One of the dropdown's is :

                            <asp:DropDownList Style="width: 100%" ID="drpStatus" runat="server" class="field select"
                                AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="SqlDataSource2_Status"
                                DataTextField="status" DataValueField="status_id">
                                <asp:ListItem Value="">All</asp:ListItem>
                            </asp:DropDownList>

Any ideas?

Thanks

like image 692
thegunner Avatar asked Feb 13 '13 16:02

thegunner


1 Answers

Sorted...just need CancelSelectOnNullParameter="false" within sqldatasource.

like image 139
thegunner Avatar answered Oct 29 '22 04:10

thegunner