Add Default Value to Dynamic asp:DropDownList With T-SQL

by Duane 26. June 2009 03:28

Why programmatically add a default value in codebehind to an asp:dropdownlist when it is easier to send it in the data result set using UNION ALL and a Sub Query?

 

-- =============================================
-- Author: Duane Urban
-- Create date: 06/26/2009
-- Description: Retreives the Book of Shadows Catagories for a dropdown list
-- =============================================
CREATE PROCEDURE [dbo].[HC_GetBOSCategories]

AS BEGIN SET NOCOUNT ON
SELECT  Id AS Value, Title AS [Key]
FROM    M_Shadow_Cat WITH (NOLOCK)
  UNION ALL
  -- Add the default value
  -- !important since we are ordering by [Key)
  -- make sure the there is a space between the
  -- char delimiter and the first letter of your
  -- default value so that it is displayed first 
  -- on your dropdown list
    (SELECT 0, ' Select Category ')
ORDER BY [Key]
END

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

ASP.NET | T-SQL

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading