Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default DropDownList

    Hi
    I looked everywhere to solve my problem but with no success. On page there
    is a dropdownlist control which is binded to a database. When I select one
    of the list item and press a button I would like to get the SelectedItem
    property, but it is always set to Nothing. What should i do? On page load I
    use Page.IsPostBack=false to load the dropdownlist only once.
    Thanks!

    Jure


    Mira Vizjak Guest

  2. Similar Questions and Discussions

    1. Dropdownlist Cascade
      Hi Guys I have two dropdownlists (A and B) Both get their values from a database When i select a value from dropdownlist A It is suppose to do...
    2. Dropdownlist help please
      Hi there, I'm a newbie to Dreamweaver MX 2004 and ASP.NET. I'm having trouble with a simple application that involves the user selecting a value...
    3. Add a dropDownList
      Hello, Could you please give me an exemple how to add a dropdownlist in a datagrid. With this following code, I bind a datatable to a datagrid,...
    4. HELP with ASP.NET DropDownList Box ! : )
      Hi all, I have a DropDownList on my page created in Design Time calledddlDate. In code, I do the following: 1 ddlDate = New DropDownList() <-...
    5. <asp:DropDownList >
      It just doesn't work like that - - you need to either bind data to the datalist in code, or manually add the items, one by one, where you're doing...
  3. #2

    Default Re: DropDownList

    Have you set AutoPostBack =true of Ddl

    Regards
    Sushila
    ..NET MVP

    "Mira Vizjak" <mira.vizjak1@guest.arnes.si> wrote in message news:berr1k$ljg$1@planja.arnes.si...
    > Hi
    > I looked everywhere to solve my problem but with no success. On page there
    > is a dropdownlist control which is binded to a database. When I select one
    > of the list item and press a button I would like to get the SelectedItem
    > property, but it is always set to Nothing. What should i do? On page load I
    > use Page.IsPostBack=false to load the dropdownlist only once.
    > Thanks!
    >
    > Jure
    >
    >
    Sonali.NET[MVP] Guest

  4. #3

    Default Re: DropDownList

    I don't want the page to reload so I can't use AutoPostBack=true.
    Mira Vizjak Guest

  5. #4

    Default Re: DropDownList

    Did you set the 'EnableViewState' to true for the dropdownlist ?

    "Mira Vizjak" <mira.vizjak1@guest.arnes.si> wrote in message
    news:berr1k$ljg$1@planja.arnes.si...
    > Hi
    > I looked everywhere to solve my problem but with no success. On page there
    > is a dropdownlist control which is binded to a database. When I select one
    > of the list item and press a button I would like to get the SelectedItem
    > property, but it is always set to Nothing. What should i do? On page load
    I
    > use Page.IsPostBack=false to load the dropdownlist only once.
    > Thanks!
    >
    > Jure
    >
    >

    Souri Challa Guest

  6. #5

    Default Re: DropDownList

    the item in a check list has a value and item text, are you setting the item
    value?

    "Mira Vizjak" <mira.vizjak1@guest.arnes.si> wrote in message
    news:berr1k$ljg$1@planja.arnes.si...
    > Hi
    > I looked everywhere to solve my problem but with no success. On page there
    > is a dropdownlist control which is binded to a database. When I select one
    > of the list item and press a button I would like to get the SelectedItem
    > property, but it is always set to Nothing. What should i do? On page load
    I
    > use Page.IsPostBack=false to load the dropdownlist only once.
    > Thanks!
    >
    > Jure
    >
    >

    dj Bass Guest

  7. #6

    Default Re: Dropdownlist

    Try this after DropDownList1.DataBind ():
    DropDownList1.SelectedIndex =
    DropDownList1.Items.IndexOf(DropDownList1.Items.Fi ndByValue(yourKnownAuthID)
    )

    What you need is basically set the selectedindex property.
    But first you find the list item that has the known Author ID.
    This (DropDownList1.Items.FindByValue(yourKnownAuthID)) returns a list item.
    This (DropDownList1.Items.IndexOf) gets the index of the listItem element
    with the known value.

    "Srinivasa Reddy K Ganji" <gksreddy@adsgroup.com> wrote in message
    news:%23TJ1mwzWDHA.1480@tk2msftngp13.phx.gbl...
    > Hi,
    >
    > I have the following code in Page_Load. I know the author id and I want
    that
    > particular author to be shown as selected in the drop downlist when the
    page
    > loads. Can anyone suggest me how to do this.
    >
    > string dsn = ConfigurationSettings.AppSettings["testDsn"];
    > SqlConnection connection = new SqlConnection (dsn);
    > SqlDataAdapter adapter = new SqlDataAdapter ("select * from authors",
    > connection);
    > DataSet ds = new DataSet ();
    > adapter.Fill (ds, "authors");
    > DropDownList1.DataSource = ds;
    > DropDownList1.DataTextField = "au_fname";
    > DropDownList1.DataValueField = "au_id";
    > DropDownList1.DataBind ();
    >
    > Thanks,
    >
    >
    > Reddy
    >
    >

    abacnet Guest

  8. #7

    Default Re: Dropdownlist

    That worked. Thanks a lot


    "abacnet" <abacnet@hotmail.com> wrote in message
    news:uVQ6u3zWDHA.1580@tk2msftngp13.phx.gbl...
    > Try this after DropDownList1.DataBind ():
    > DropDownList1.SelectedIndex =
    >
    DropDownList1.Items.IndexOf(DropDownList1.Items.Fi ndByValue(yourKnownAuthID)
    > )
    >
    > What you need is basically set the selectedindex property.
    > But first you find the list item that has the known Author ID.
    > This (DropDownList1.Items.FindByValue(yourKnownAuthID)) returns a list
    item.
    > This (DropDownList1.Items.IndexOf) gets the index of the listItem element
    > with the known value.
    >
    > "Srinivasa Reddy K Ganji" <gksreddy@adsgroup.com> wrote in message
    > news:%23TJ1mwzWDHA.1480@tk2msftngp13.phx.gbl...
    > > Hi,
    > >
    > > I have the following code in Page_Load. I know the author id and I want
    > that
    > > particular author to be shown as selected in the drop downlist when the
    > page
    > > loads. Can anyone suggest me how to do this.
    > >
    > > string dsn = ConfigurationSettings.AppSettings["testDsn"];
    > > SqlConnection connection = new SqlConnection (dsn);
    > > SqlDataAdapter adapter = new SqlDataAdapter ("select * from authors",
    > > connection);
    > > DataSet ds = new DataSet ();
    > > adapter.Fill (ds, "authors");
    > > DropDownList1.DataSource = ds;
    > > DropDownList1.DataTextField = "au_fname";
    > > DropDownList1.DataValueField = "au_id";
    > > DropDownList1.DataBind ();
    > >
    > > Thanks,
    > >
    > >
    > > Reddy
    > >
    > >
    >
    >

    Reddy Guest

  9. #8

    Default DropDownList

    Hello to all.

    I´m trying to use a string, to build the ListItem's of a
    DropDownList.

    I declare a Public str as string in the webform1.aspx.vb,
    and in the page load I build the string like this:

    str = "<asp:ListItem value='0'>Blue</asp:ListItem>
    <asp:ListItem value='1'>Red</asp:ListItem>"

    In the webform1.aspx, html mode, I call the str within the
    tag <asp:DropDownList>, like this <%str%>. As I expected,
    it gives an error, saying that I can't use this type of
    calls.

    I want to Know, if it's possible to do something like we
    do in asp to build a select object using a string with the
    <options>.

    Thank you all.

    Best wishes.

    Ana Rita



    Ana Rita Guest

  10. #9

    Default DropDownList

    In a drop down list you can assing the value from
    recordset like this:
    country.DataTextField = "country"
    country.DataValueField = "Code"
    What if I need to assign more value to a DataValueField
    from a recordset. Something like this:
    country.DataTextField = "country"
    country.DataValueField(1) = "Code"
    country.DataValueField(2) = "Code1"
    How do I do this?

    anonymous Guest

  11. #10

    Default Re: DropDownList

    Merge all values into one string and that parse it?

    Eliyahu

    "anonymous" <anonymous@discussions.microsoft.com> wrote in message
    news:1fee301c4588f$11aaf280$a101280a@phx.gbl...
    > In a drop down list you can assing the value from
    > recordset like this:
    > country.DataTextField = "country"
    > country.DataValueField = "Code"
    > What if I need to assign more value to a DataValueField
    > from a recordset. Something like this:
    > country.DataTextField = "country"
    > country.DataValueField(1) = "Code"
    > country.DataValueField(2) = "Code1"
    > How do I do this?
    >

    Eliyahu Goldin Guest

  12. #11

    Default DropDownList

    Hi All,
    I have an ASPX Page, and I want to create "Dropdown list" in the run time
    and then upload its content to a database
    Could any one help me on how to do this?



    Marwa Bahaa Guest

  13. #12

    Default DropDownList

    Hello folks,
    I have a database table with CategoryID, Name and Description. I
    made 2 DropDown Lists one for Displaying Name and the other for
    Description. I want to add a web control, lets say a simple Datagrid
    that would display the CategoryID depending on the values selected
    from the 2 drop down lists. Can some one help me with this please? C#
    web forms would be very helpful.

    sqlDataAdapter1.Fill(dsCategories11);
    DataGrid1.DataBind();
    DropDownList1.DataBind();
    DropDownList2.DataBind(); //upto this
    point data is binded to the ddlist and everything is fine...

    sqlDataAdapter1.SelectCommand.CommandText="SELECT CategoryID FROM
    Categories WHERE CategoryName="+DropDownList1.SelectedItem.ToString ();
    sqlDataAdapter1.Fill(dsCategories121);
    Datagrid2.DataBind();

    //after this I get an error saying "Invalid Coloumn name 'Beverage'
    which is the item selected in the drop down list 1.

    Please help...
    Thanks
    Seelan
    Seelan Guest

  14. #13

    Default Re: DropDownList

    Hi,

    I don't know what you're using for your database software, but just as
    a suggestion, can you reproduce the full query string along with the
    parameter 'Beverage' from the web page and run it in the DB software
    itself?

    I have a similar setup to yours but it's only using one DDL, and if I
    change part of the query by adding a letter to one of the parameters,
    say in your case making "CategoryName" into "CategoryName1," it would
    give me the same error but instead of it saying "invalid column name
    'beverage'" it would say invalid column name 'CategoryName1'.

    You may want to check what your DDL1.DataMember equals as well...
    I suppose it could also be that there is some kind of disconnect
    between your query and your dsCategor*ies121...

    HTH.

    EJD Guest

  15. #14

    Default DropDownList

    Hello


    I have to dropdownlists on my page: one containing project names, second
    containing project versions. I would like to refresh the contents of the
    second dropdownlist right after the selected item in the first
    dropdownlist is changed. I tried the SelectedIndexChanged event but it
    didn't work.


    Regards,

    Wojtek
    Wojtek Guest

  16. #15

    Default Re: DropDownList

    Please read this first:
    [url]http://www.aspfaq.com/show.asp?id=2081[/url] (Specifically, bullet #2)

    Then check this out:
    [url]http://www.aspfaq.com/show.asp?id=2270[/url]

    Ray at work

    "Wojtek" <wojteku@forcom.com.pl> wrote in message
    news:dc7ebr$1r3$1@inews.gazeta.pl...
    > Hello
    >
    >
    > I have to dropdownlists on my page: one containing project names, second
    > containing project versions. I would like to refresh the contents of the
    > second dropdownlist right after the selected item in the first
    > dropdownlist is changed. I tried the SelectedIndexChanged event but it
    > didn't work.
    >
    >
    > Regards,
    >
    > Wojtek

    Ray Costanzo [MVP] Guest

  17. #16

    Default Re: DropDownList

    Ray Costanzo [MVP] napisał(a):
    > Please read this first:
    > [url]http://www.aspfaq.com/show.asp?id=2081[/url] (Specifically, bullet #2)
    >
    > Then check this out:
    > [url]http://www.aspfaq.com/show.asp?id=2270[/url]
    >
    > Ray at work
    >
    > "Wojtek" <wojteku@forcom.com.pl> wrote in message
    > news:dc7ebr$1r3$1@inews.gazeta.pl...
    >
    >>Hello
    >>
    >>
    >>I have to dropdownlists on my page: one containing project names, second
    >>containing project versions. I would like to refresh the contents of the
    >>second dropdownlist right after the selected item in the first
    >>dropdownlist is changed. I tried the SelectedIndexChanged event but it
    >>didn't work.
    >>
    >>
    >>Regards,
    >>
    >>Wojtek
    >
    >
    >
    I didn't mention, that I am using C#. I couldn't find any examples
    except that using Javascript. Is it possible to achieve this using C#?

    Regards,

    Wojtek
    Wojtek Guest

  18. #17

    Default Re: DropDownList

    In that case, you'd want to see an ASP.Net group. This is a classic ASP
    group. Check out the groups with "aspnet" in their names and post there,
    but still not until after reading [url]http://www.aspfaq.com/show.asp?id=2081[/url]!

    Ray at work

    "Wojtek" <wojteku@forcom.com.pl> wrote in message
    news:dcam66$12f$1@inews.gazeta.pl...
    > >
    > >
    >
    > I didn't mention, that I am using C#. I couldn't find any examples
    > except that using Javascript. Is it possible to achieve this using C#?
    >
    > Regards,
    >
    > Wojtek

    Ray Costanzo [MVP] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139