Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6537849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:39:56+00:00 2026-05-25T10:39:56+00:00

I am making a WebForm in asp.net and I want to display gridview with

  • 0

I am making a WebForm in asp.net and I want to display gridview with data from asp:SqlDataSource
My problem becomes when I try to skip (pass null) values for some of the Parameters.

Here is some snippets of my code

In aspx file sqldatasource looks like

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
        SelectCommand="art_bat_art" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="art_naz" DefaultValue="HLA"  ConvertEmptyStringToNull="true" Type="String" />
            <asp:Parameter Name="art_sifra"     DbType="String"  Direction="Input"/>
            <asp:Parameter Name="vrsta_id" DefaultValue="3"   ConvertEmptyStringToNull="true" Type="Int32" />     
            <asp:Parameter Name="podvrsta_id" DefaultValue="13"   ConvertEmptyStringToNull="true" 
                Type="Int32"  />
            <asp:Parameter Name="podgrupa2"  DefaultValue="1365"   ConvertEmptyStringToNull="true" Type="Int32"      /> 
            <asp:Parameter Name="podosobine"   DefaultValue="1:9241"  ConvertEmptyStringToNull="true" 
                Type="String"  />
            <asp:Parameter Name="podosobineOR" DefaultValue="true"   ConvertEmptyStringToNull="true" 
                Type="Boolean"  />
        </SelectParameters>

My grid looks like this:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1">

And troubles comes in code behind
One of parameters for my stored procedure is optional, If i pass it as null in SQL the stored procedure is
going to execute anyway.

I am trying to skip and pass that parameter as follows

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }
        protected void Button1_Click1(object sender, EventArgs e)
        {
            SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = DBNull.Value; //Cannot implicitly convert type 
            SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = System.Data.SqlTypes.SqlString.Null;   //Cannot implicitly convert type 
            SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = System.Data.SqlTypes.SqlString.Null.ToString();   //IT compiles but i get NULL as text in SQL
            //IF I Just skip seting of this parametar, My SqlDataSource won't call stored proce 
            SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = string.Empty; //Again no execution of stored proce
            //Even if I call SqlDataSource1.DataBind(); //nothing cames to sql 
            GridView1.DataBind();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:39:57+00:00Added an answer on May 25, 2026 at 10:39 am

    You’ll have to edit your SQL (or stored proc) to be able to handle an optional parameter.

    ie: if you have:

    SELECT blah FROM yourTable WHERE art_sifra = @art_sifra

    change it to:
    SELECT blah FROM yourTable WHERE (art_sifra = @art_sifra OR @art_sifra = '')

    and then just change ConvertEmptyStringToNull="false" and set your select parameter to "":
    SqlDataSource1.SelectParameters["art_sifra"].DefaultValue = "";

    Also need to set CancelSelectOnNullParameter="false" on your datasource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our ASP.NET WebForms MasterPage is making a muck of our meta data and title.
I am just making a demo application and want to configure asp.net to use
I'm having trouble with this simple scenario. First, I'm using ASP.NET WebForms. I'm making
I've been working in asp.net webforms and I've been making a UserControl that depends
Within an asp webform project I am making a call to a web service
I am making an asp.net, c#, webforms web site for sales clerks. I have
I am using the ReportViewer control in an ASP.NET WebForms application to display (and
Actually i am making website of online test/exam in asp.net using c# 4.0. And
Making an adobe flex ui in which data that is calculated must use proprietary
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.