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
Tags: union all, default value, sql, asp:dropdownlist, t-sql
ASP.NET | T-SQL