DetailsView and dropdownlist
-
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
-
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
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
-
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
-
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 ;)
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.
-
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
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 ??
-
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 ??
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.
-
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.