We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 04/10/08


Tagged

c-sharp


Versions (?)


DropDown List Control


Published in: C# 


  1. <asp:DropDownList ID="ddlList" runat="server" />
  2.  
  3. <asp:RequiredFieldValidator ID="rfvList" ControlToValidate="ddlList"
  4. runat="server" EnableClientScript="false" CssClass="validation">*</asp:RequiredFieldValidator>
  5.  
  6.  
  7. ddlList.DataSource = DataSelection.ReturnDataTable("sp_StoredProc");
  8.  
  9. ddlList.DataValueField = "item_value";
  10. ddlList.DataTextField = "display_text";
  11. ddlList.DataBind();
  12.  
  13. ddlList.Items.Insert(0, new ListItem("--Select--", ""));
  14.  
  15. if (ddlList.Items.FindByValue("") != null)
  16. ddlList.Items.FindByValue("").Selected = true;
  17.  
  18.  
  19.  
  20. public string SelectedValue
  21. {
  22. get
  23. {
  24. return ddlList.SelectedValue;
  25. }
  26. set
  27. {
  28. ddlList.SelectedValue = value;
  29. }
  30. }
  31.  
  32. public string Width
  33. {
  34. set
  35. {
  36. ddlCountries.Width = value;
  37. }
  38. }
  39.  
  40. public string id
  41. {
  42. set
  43. {
  44. ddlList.ID = value;
  45. }
  46. }
  47.  
  48. public string ValidationEnabled
  49. {
  50. set
  51. {
  52. rfvList.Enabled = Convert.ToBoolean(value);
  53. }
  54. }
  55.  
  56.  
  57. public string ValidationGroup
  58. {
  59. set
  60. {
  61. ddlList.ValidationGroup = value;
  62. }
  63. }
  64.  
  65. public string ValidationErrorMessage
  66. {
  67. set
  68. {
  69. rfvList.ErrorMessage = value;
  70. }
  71. }
  72.  
  73. public short TabIndex
  74. {
  75. set
  76. {
  77. ddlList.TabIndex = value;
  78. }
  79. }

Report this snippet 

You need to login to post a comment.