dropdownlist box

Results 1 to 2 of 2

Thread: dropdownlist box

  1. #1
    Join Date
    Dec 1969

    Default dropdownlist box

    Hi i am doing app in asp.net<BR>I want to display desc,id in dropdownlist box here id is hidden<BR>when refer the dropdownlist value i want capture the id.<BR><BR>I am doing like this<BR>&#060;asp:DropDownList id = "list1" DataSource="&#060;%# BindTheRepHead() %&#062;" OnPreRender="SetDropDownIndex" DataTextField="desc" DataValueField="id" Runat =server /&#062;<BR>but listbox showing null.Is there any other way to do .<BR>How to bind the sql query to listbox.

  2. #2
    Join Date
    Dec 1969

    Default RE: dropdownlist box

    If you are using SQL Server this will do it:<BR>&#060;script&#062;<BR>Sub Page_Load<BR>If Not IsPostBack Then<BR>Dim ConSQL as SQLConnection<BR>Dim CmdSelect as SQLCommand<BR>Dim StrSelect as String<BR><BR>ConSQL = New SQLConnection("&#060;---your connection String----&#062;")<BR>StrSelect = "Select id, desc from Table"<BR>CmdSelect as New SQLCommand(StrSelect, ConSQL)<BR>ConSQL.open()<BR>List1.datasource = CmdSelect.executereader()<BR>List1.DataValueField = "ID"<BR>list1.datatextField = "Desc"<BR>List1.databind()<BR>ConSQL.Close()<BR>En d If<BR>End Sub<BR><BR>&#060;/script&#062;<BR><BR>&#060;html&#062; etc etc<BR><BR>&#060;asp:DropDownList<BR>id=List1<BR>r unat=server/&#062;<BR><BR>I&#039;ve got a great book called asp.net unleashed which covers all of this in detail - its worth a read<BR><BR>Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts