title: VB.NET TO C# - Gridview Code behind for a search from a listbox w a stored procedure
body: <p>I am looking for the correct code behind syntax in C# for displaying Search Results from multiple parameters in Gridview. I just did something similar in VB.NET but I have to update a project in C#.NET and am unsure of:</p>
  
  <p>1) the correct codebehind syntax in C#.NET (code in VB.NET)</p>
  
  <p>2) how to specify multiple search paramaters in the case that a user selects multiple Insurance Plan parameters, Multiple Age parameters, and/or M from a Listbox</p>
  
  <p>3) disable or enable the ability to select multiple parameters in a listbox. (For State and Zip List boxes I'd like to disable selecting multiple parameters and on Plan, Age, and Carrier I'd like to enable selecting multiple parameters. </p>
  
  <p>Here's what I have on the backend in VB.NET that needs to be in C#.NET: </p>
  
  <pre><code>      Protected Sub SearchButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SearchButton.Click
          With Me.SqlDataSource1
          .SelectParameters.Clear()
  
          .ConnectionString = ConfigurationManager.AppSettings("PriceFinderConnectionString").ToString
          .SelectCommand = "up_SelectPriceFinderResults" //calling stored procedure 
          .SelectParameters.Add("state_code", Me.lastname.Text)
          .SelectParameters.Add("zip_code", Me.city.Text)
          .SelectParameters.Add("plan_name", Me.state.Text)
          .SelectParameters.Add("age", Me.state.Text)
          .SelectParameters.Add("carrier_name", Me.donotmail.Text)
  
          .SelectParameters(0).ConvertEmptyStringToNull = True
          .SelectParameters(1).ConvertEmptyStringToNull = True
          .SelectParameters(2).ConvertEmptyStringToNull = True
          .SelectParameters(3).ConvertEmptyStringToNull = True
          .SelectParameters(4).ConvertEmptyStringToNull = True
          .SelectCommandType = SqlDataSourceCommandType.StoredProcedure
  
          .CancelSelectOnNullParameter = False
  
      End With
  
      GridView2.DataBind()
    End Sub
  </code></pre>
  
  <p>Here's the code for the stored procedure: </p>
  
  <pre><code>PROCEDURE [dbo].[up_SelectPriceFinderResults] 
  -- Add the parameters for the stored procedure here
  @state_code varchar(20)= NULL, 
  @zip_code varchar(20)= NULL,
       @plan_code varchar(2)= NULL, 
       @insur_age varchar(2)= NULL,
  @carrier_name varchar(20)= NULL,
  
       AS
       BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  
  SET NOCOUNT ON;
  
  -- Insert statements for procedure here
  
  IF len(@state_code)=0 
     BEGIN SET @state_code=NULL
     END
  IF len(@zip_code)=0
     BEGIN SET @zip_code=NULL 
     END  
  IF len(@plan_name)=0
     BEGIN SET @plan_code=NULL
     END
  IF len(@insur_age)=0
     BEGIN SET @age=NULL
     END
  IF len(@carrier_name)=0
     BEGIN SET @carrier_name=NULL
     END
  
  
  SELECT  [state_code], 
      [zip_code], 
      [plan_code], 
      [carrier_name],
      [insur_age],  
              [female_value],
      [male_value]        
          CASE WHEN [female_value] is NULL OR 0 
              THEN 'N/A'
          END AS 'female_value',
          CASE WHEN [male_value] is NULL OR 0 
              THEN 'N/A'
          END AS 'male_value',
  FROM 
         [state_zipcode_plans] 
  WHERE
          (([state_code] = @state_code OR @state_code IS NULL) 
      AND ([zip_code] = @zip_code OR @zip_code IS NULL) 
      AND ([plan_name] = @plan_name OR @plan_name IS NULL) 
      AND ([insur_age] = @insur_age OR @insur_age IS NULL)
      AND ([carrier_name] = @carrier_name OR @carrier_name IS NULL))
  
  ORDER BY 
         [plan_code], [female_value], [male_value]
  END
  </code></pre>