DropDownList control in DataGrid

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

  1. #1

    Default DropDownList control in DataGrid

    Hello all,

    I'l displaying a dropdownlist inside a datagrid. The problem comes when I
    try to get the values the user chose on postback.

    If I rebind the datagrid, the values of the dropdownlist are all set back to
    their original values. If I do not rebind the datagrid, I don't seem to have
    access to the dropdownlist at all.

    Code fragment:

    For Each dgItem In Me.dgPlayerList.Items
    strID = dgItem.Cells(0).Text
    Dim ddlTeam As New DropDownList()
    ddlTeam = dgItem.FindControl("ddlTeams")
    strTeam = ddlTeam.SelectedItem.Value

    I get the "Object reference not set to an instance of an object" on the last
    line there when I do not rebind. I was under the impression that datagrids
    had to be rebound on postback to access their contents, but I'm obviously
    missing something. Hopefully something simple.

    Thanks for any suggestions,

    pete



    pete Guest

  2. Similar Questions and Discussions

    1. Dropdownlist Control in DataGrid Not Updating After Databind
      I seem to be having trouble getting my Datagrid label to Update correctly after clicking on update from a dropdownlist. I implemented the scheme...
    2. Respond to DropDownList control Event in DataGrid
      I am adding a DropDownList control to my DataGrid footer template. I load my DropDownList using a function that returns an arrayList. I can see...
    3. dropdownlist control
      I have a form which displays a number of text boxes that are all data bound to a dataset. I want to change one of these text boxes to be a drop...
    4. How to Bind a DropDownList control to a DataGrid in Template Column?
      I'm having a tough time with this, and I can't find any resources that address it. I have a DataGrid comprised of Template Columns, in which I have...
    5. Error Binding DropDownList on EditItem Command of DataGrid Control
      I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a...
  3. #2

    Default Re: DropDownList control in DataGrid

    You don't have to rebind the grid on postback.
    Where in the code are you trying to get the selected values? You should be
    doing it after Page_Load has completed. Preferably inthe event handler of
    the control that triggered the post back.

    --
    Naveen K Kohli
    [url]http://www.netomatix.com[/url]
    "pete" <peter@invalid.com> wrote in message
    news:uQsZ5lAQDHA.2052@TK2MSFTNGP11.phx.gbl...
    > Hello all,
    >
    > I'l displaying a dropdownlist inside a datagrid. The problem comes when I
    > try to get the values the user chose on postback.
    >
    > If I rebind the datagrid, the values of the dropdownlist are all set back
    to
    > their original values. If I do not rebind the datagrid, I don't seem to
    have
    > access to the dropdownlist at all.
    >
    > Code fragment:
    >
    > For Each dgItem In Me.dgPlayerList.Items
    > strID = dgItem.Cells(0).Text
    > Dim ddlTeam As New DropDownList()
    > ddlTeam = dgItem.FindControl("ddlTeams")
    > strTeam = ddlTeam.SelectedItem.Value
    >
    > I get the "Object reference not set to an instance of an object" on the
    last
    > line there when I do not rebind. I was under the impression that datagrids
    > had to be rebound on postback to access their contents, but I'm obviously
    > missing something. Hopefully something simple.
    >
    > Thanks for any suggestions,
    >
    > pete
    >
    >
    >

    Naveen K Kohli 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