Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DetailsView and dropdownlist

DetailsView and dropdownlist

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netsysadminquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sandraa
    wrote on last edited by
    #1

    Hi all, i have a little problem that even i don't know like solve. I know that is possible but I don't know how. I have a project ASP.NET with VBasic.NET I want to add a dropdownlist to DetailsView with diferent source that detailsview. I put my code and the error:

                    Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)
                    Dim UsuariosServicios As New DataTable
                    UsuariosServicios = Servicios.ObtenerUsuariosServicios()
                    InsertComboUsuarios.DataSource = UsuariosServicios
                    InsertComboUsuarios.DataTextField = UsuariosServicios.Columns("Usuario").ColumnName.ToString()
                    InsertComboUsuarios.DataValueField = UsuariosServicios.Columns("IdUsuario").ColumnName.ToString()
                    InsertComboUsuarios.DataBind()
    

    the code in aspx:

                    <asp:TemplateField HeaderText="Usuario del Servicio" >
                     <ItemTemplate>
                        <asp:Label ID="lblUsuario" Text='<%# Eval("Id\_Usuario") %>' runat="server"></asp:Label>
                     </ItemTemplate>
                     <EditItemTemplate>
                        <asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
                    </InsertItemTemplate>
                    </asp:TemplateField>  
    

    and the error is: System.NullReferenceException was caught Message="Referencia a objeto no establecida como instancia de un objeto." Source="App_Web_ie3hu1zc" The source failed when pass by InsertComboUsuarios.DataSource = UsuariosServicios some idea? thanks very much for your help

    M N 2 Replies Last reply
    0
    • S Sandraa

      Hi all, i have a little problem that even i don't know like solve. I know that is possible but I don't know how. I have a project ASP.NET with VBasic.NET I want to add a dropdownlist to DetailsView with diferent source that detailsview. I put my code and the error:

                      Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)
                      Dim UsuariosServicios As New DataTable
                      UsuariosServicios = Servicios.ObtenerUsuariosServicios()
                      InsertComboUsuarios.DataSource = UsuariosServicios
                      InsertComboUsuarios.DataTextField = UsuariosServicios.Columns("Usuario").ColumnName.ToString()
                      InsertComboUsuarios.DataValueField = UsuariosServicios.Columns("IdUsuario").ColumnName.ToString()
                      InsertComboUsuarios.DataBind()
      

      the code in aspx:

                      <asp:TemplateField HeaderText="Usuario del Servicio" >
                       <ItemTemplate>
                          <asp:Label ID="lblUsuario" Text='<%# Eval("Id\_Usuario") %>' runat="server"></asp:Label>
                       </ItemTemplate>
                       <EditItemTemplate>
                          <asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
                      </EditItemTemplate>
                      <InsertItemTemplate>
                          <asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
                      </InsertItemTemplate>
                      </asp:TemplateField>  
      

      and the error is: System.NullReferenceException was caught Message="Referencia a objeto no establecida como instancia de un objeto." Source="App_Web_ie3hu1zc" The source failed when pass by InsertComboUsuarios.DataSource = UsuariosServicios some idea? thanks very much for your help

      M Offline
      M Offline
      Marcelo Emmerich
      wrote on last edited by
      #2

      Hi Sandraa, I have done this many times. I don't know exactly why it does not work for you (did not try it out), however, I want to show you a snippet of my working code. Besides being C# the main difference is that I use declarative syntax only: First the dropdown declaration in the .aspx file: SelectedValue='<%# Bind("fake_flag1")%>' ID="ddl_test1" DataSourceID="TestDS" DataTextField="someDescription" DataValueField="someID" runat="server"> Next the declaration of the datasource for the above dropdown, which is different of the detailsview the dropdown is in: SelectCommand="SELECT * FROM TEST"> Hope this helps. Maybe the problem in your code is the point in time when you try to set the datasource? Cheers, Marcelo

      -- Marcelo Emmerich Software Development - Computer Graphics - Mobile Computing http://bytethings.blogspot.com

      S 1 Reply Last reply
      0
      • M Marcelo Emmerich

        Hi Sandraa, I have done this many times. I don't know exactly why it does not work for you (did not try it out), however, I want to show you a snippet of my working code. Besides being C# the main difference is that I use declarative syntax only: First the dropdown declaration in the .aspx file: SelectedValue='<%# Bind("fake_flag1")%>' ID="ddl_test1" DataSourceID="TestDS" DataTextField="someDescription" DataValueField="someID" runat="server"> Next the declaration of the datasource for the above dropdown, which is different of the detailsview the dropdown is in: SelectCommand="SELECT * FROM TEST"> Hope this helps. Maybe the problem in your code is the point in time when you try to set the datasource? Cheers, Marcelo

        -- Marcelo Emmerich Software Development - Computer Graphics - Mobile Computing http://bytethings.blogspot.com

        S Offline
        S Offline
        Sandraa
        wrote on last edited by
        #3

        Thanks Marcelo but your code is for aspx and I am using aspx.vb, I don't know like call well to dropdownlist from aspx.vb page and from detailsview. Remenber that my dropdownlist is into a detailsview :( Thanks for all ;)

        C 1 Reply Last reply
        0
        • S Sandraa

          Thanks Marcelo but your code is for aspx and I am using aspx.vb, I don't know like call well to dropdownlist from aspx.vb page and from detailsview. Remenber that my dropdownlist is into a detailsview :( Thanks for all ;)

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Sandraa wrote:

          but your code is for aspx and I am using aspx.vb

          Yes, he said you'd have to convert C# to VB, that's trivial to do. Also, he said he's doing it in the aspx, is there any reason you can't try it that way ?

          Christian Graus Driven to the arms of OSX by Vista.

          1 Reply Last reply
          0
          • S Sandraa

            Hi all, i have a little problem that even i don't know like solve. I know that is possible but I don't know how. I have a project ASP.NET with VBasic.NET I want to add a dropdownlist to DetailsView with diferent source that detailsview. I put my code and the error:

                            Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)
                            Dim UsuariosServicios As New DataTable
                            UsuariosServicios = Servicios.ObtenerUsuariosServicios()
                            InsertComboUsuarios.DataSource = UsuariosServicios
                            InsertComboUsuarios.DataTextField = UsuariosServicios.Columns("Usuario").ColumnName.ToString()
                            InsertComboUsuarios.DataValueField = UsuariosServicios.Columns("IdUsuario").ColumnName.ToString()
                            InsertComboUsuarios.DataBind()
            

            the code in aspx:

                            <asp:TemplateField HeaderText="Usuario del Servicio" >
                             <ItemTemplate>
                                <asp:Label ID="lblUsuario" Text='<%# Eval("Id\_Usuario") %>' runat="server"></asp:Label>
                             </ItemTemplate>
                             <EditItemTemplate>
                                <asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
                            </InsertItemTemplate>
                            </asp:TemplateField>  
            

            and the error is: System.NullReferenceException was caught Message="Referencia a objeto no establecida como instancia de un objeto." Source="App_Web_ie3hu1zc" The source failed when pass by InsertComboUsuarios.DataSource = UsuariosServicios some idea? thanks very much for your help

            N Offline
            N Offline
            Nishant Singh
            wrote on last edited by
            #5

            Hi Sandraa, Are you sure

            Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)

            This line is returning you a DropDownList object ??? That is to say InsertComboUsuarios is not null ??

            S 1 Reply Last reply
            0
            • N Nishant Singh

              Hi Sandraa, Are you sure

              Dim InsertComboUsuarios As DropDownList = DirectCast(detailsView.FindControl("InsertComboUsuarios"), DropDownList)

              This line is returning you a DropDownList object ??? That is to say InsertComboUsuarios is not null ??

              S Offline
              S Offline
              Sandraa
              wrote on last edited by
              #6

              I believe that yes, I put you the code in aspx page

                              <asp:TemplateField HeaderText="Usuario del Servicio" >
                               <ItemTemplate>
                                  <asp:Label ID="lblUsuario" Text='<%# Eval("Id\_Usuario") %>' runat="server"></asp:Label>
                               </ItemTemplate>
                               <EditItemTemplate>
                                  <asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
                              </EditItemTemplate>
                              <InsertItemTemplate>
                                  <asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
                              </InsertItemTemplate>
                              </asp:TemplateField> 
              

              I believe that I have put something bad in this code. Thanks for your help.

              S 1 Reply Last reply
              0
              • S Sandraa

                I believe that yes, I put you the code in aspx page

                                <asp:TemplateField HeaderText="Usuario del Servicio" >
                                 <ItemTemplate>
                                    <asp:Label ID="lblUsuario" Text='<%# Eval("Id\_Usuario") %>' runat="server"></asp:Label>
                                 </ItemTemplate>
                                 <EditItemTemplate>
                                    <asp:DropDownList ID="EditComboUsuarios" runat="server"></asp:DropDownList>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:DropDownList ID="InsertComboUsuarios" runat="server"></asp:DropDownList>
                                </InsertItemTemplate>
                                </asp:TemplateField> 
                

                I believe that I have put something bad in this code. Thanks for your help.

                S Offline
                S Offline
                Sandraa
                wrote on last edited by
                #7

                S.O.S Even I continue with this problem, please any idea?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups