hard code data bind

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • si_owen

    #1

    hard code data bind

    Hi all,

    firstly this is a web apps project.

    Right i had a dropdown list which was populated by a db table which was
    databound using a sql datasource.

    however when adding validation controls the dropdownlist was failing as
    an item was already selected. I need a default value in there "please
    select one" to appear when the page is loaded or postback occurs. This
    dropdownlist item cannot appear in the db but must appear in the list
    and appear first before the other items populated by the db.

    I have deleted the databond between sql datasource and the dropdownlist
    and have written a select statement to grab the categories. i need to
    add the "please select one" item before the db is called and then loop
    untill all records from the db have been populated into the drop down
    list.

    all i have so far is below:

    Protected Sub DropDownList1_D ataBinding(ByVa l sender As Object,
    ByVal e As System.EventArg s) Handles DropDownList1.D ataBinding

    Dim SelectCategory As New SqlCommand
    Dim ConCategory As New
    SqlConnection(d ataCategories.C onnectionString )
    Dim Param As New SqlParameter("@ CategoryID",
    Data.SqlDbType. Int)

    DropDownList1.I tems.Add("Pleas e Select One")

    SelectCategory. CommandText = "SELECT category FROM [faq
    category] WHERE categoryID = @categoryid"
    ConCategory.Ope n()

    Dim reader As SqlDataReader = SelectCategory. ExecuteReader
    While reader.Read
    DropDownList1.S electedItem.Val ue = reader(0)
    End While
    ConCategory.Clo se()

    End Sub

    probably going the wrong way with but thats why i need your help.

    many thanks

    simon

  • Ryan S. Thiele

    #2
    Re: hard code data bind

    Have you tried setting the text of the combobox to "Select One" then it
    should show as default.

    --
    Thiele Enterprises - The Power Is In Your Hands Now!

    --
    "si_owen" <s.owen@sstaffs .gov.ukwrote in message
    news:1161355495 .976941.179880@ h48g2000cwc.goo glegroups.com.. .
    Hi all,

    firstly this is a web apps project.

    Right i had a dropdown list which was populated by a db table which was
    databound using a sql datasource.

    however when adding validation controls the dropdownlist was failing as
    an item was already selected. I need a default value in there "please
    select one" to appear when the page is loaded or postback occurs. This
    dropdownlist item cannot appear in the db but must appear in the list
    and appear first before the other items populated by the db.

    I have deleted the databond between sql datasource and the dropdownlist
    and have written a select statement to grab the categories. i need to
    add the "please select one" item before the db is called and then loop
    untill all records from the db have been populated into the drop down
    list.

    all i have so far is below:

    Protected Sub DropDownList1_D ataBinding(ByVa l sender As Object,
    ByVal e As System.EventArg s) Handles DropDownList1.D ataBinding

    Dim SelectCategory As New SqlCommand
    Dim ConCategory As New
    SqlConnection(d ataCategories.C onnectionString )
    Dim Param As New SqlParameter("@ CategoryID",
    Data.SqlDbType. Int)

    DropDownList1.I tems.Add("Pleas e Select One")

    SelectCategory. CommandText = "SELECT category FROM [faq
    category] WHERE categoryID = @categoryid"
    ConCategory.Ope n()

    Dim reader As SqlDataReader = SelectCategory. ExecuteReader
    While reader.Read
    DropDownList1.S electedItem.Val ue = reader(0)
    End While
    ConCategory.Clo se()

    End Sub

    probably going the wrong way with but thats why i need your help.

    many thanks

    simon


    Comment

    • si_owen

      #3
      Re: hard code data bind

      yes that was the first thing i tried, but the drag and drop data bind
      over rides cjanging the text property in the properties.

      Comment

      Working...