Jump to content
dicas3d

Dropdownlist dentro detailview dá erro.

Recommended Posts

dicas3d

Olá.

Preciso de por numa detailsview no edit template uma dropdownlist com os nomes dos ISV's, porem esta dá runtime error ao por a detailsview em edit mode.

O erro é:

Server Error in '/PAP_site' Application.
'ddlISV' has a SelectedValue which is invalid because it does not exist in the list of items.
Nome do parâmetro: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddlISV' has a SelectedValue which is invalid because it does not exist in the list of items.
Nome do parâmetro: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: 'ddlISV' has a SelectedValue which is invalid because it does not exist in the list of items.
Nome do parâmetro: value]
   System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +1768525
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +109
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.Control.DataBindChildren() +201
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +201
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +201
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +201
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
   System.Web.UI.WebControls.DetailsView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1760
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66
   System.Web.UI.WebControls.DetailsView.PerformDataBinding(IEnumerable data) +12
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.DetailsView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.DetailsView.EnsureDataBound() +228
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

código:

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
                    Height="50px" Width="354px" DefaultMode="Edit">
                    <Fields>
                        <asp:TemplateField HeaderText="Nome" SortExpression="Nome">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Nome") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrNome2" runat="server" ControlToValidate="TextBox2"
                                    ErrorMessage="O campo Nome está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="txtNome" runat="server" Text='<%# Bind("Nome") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrNome" runat="server" ControlToValidate="txtNome"
                                    ErrorMessage="O campo Nome está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Nome") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Marca" SortExpression="Marca">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Marca") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrMarca2" runat="server" ControlToValidate="TextBox3"
                                    ErrorMessage="O campo Marca está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="txtMarca" runat="server" Text='<%# Bind("Marca") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrMarca" runat="server" ControlToValidate="txtMarca"
                                    ErrorMessage="O campo Marca está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Marca") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Preço Base" SortExpression="Preco_Base">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Preco_Base") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrPreco_Base2" runat="server" ControlToValidate="TextBox4"
                                    ErrorMessage="O campo Preço Base está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="txtPreco_Base" runat="server" Text='<%# Bind("Preco_Base") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rqrPreco_Base" runat="server" ControlToValidate="txtPreco_Base"
                                    ErrorMessage="O campo Preço Base está vazio." BackColor="Yellow" ForeColor="Red"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Preco_Base") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="ISV" SortExpression="Cod_ISV">
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlISV" runat="server" AppendDataBoundItems="True" 
                                    SelectedValue='<%# Bind("Cod_ISV") %>'>
                                    <asp:ListItem Value="" Text="" />
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlISV" DataSourceID="ISV" DataValueField="Cod_ISV" DataTextField="Nome_ISV"
                                    SelectedValue='<%# Bind("Cod_ISV") %>' runat="server">
                                </asp:DropDownList>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Cod_ISV") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="CC" HeaderText="CC" SortExpression="CC" />
                        <asp:BoundField DataField="Potencia" HeaderText="Potência" SortExpression="Potencia" />
                        <asp:BoundField DataField="binario" HeaderText="Binário" SortExpression="binario" />
                        <asp:BoundField DataField="transmissao" HeaderText="Transmissao" SortExpression="transmissao" />
                        <asp:BoundField DataField="consumo" HeaderText="Consumo" SortExpression="consumo" />
                        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
                    </Fields>
                </asp:DetailsView>
                <asp:SqlDataSource ID="ISV" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                    SelectCommand="SELECT [Cod_ISV], [Nome_ISV] FROM [iSV]"></asp:SqlDataSource>
                <asp:SqlDataSource runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                    ID="SqlDataSource1" InsertCommand="INSERT INTO Carro(Cod_Carro, Marca, Preco_Base, Cod_ISV, Nome, consumo, transmissao, binario, Potencia, CC) VALUES (@Cod_Carro, @Marca, @Preco_Base, @Cod_ISV, @Nome, @consumo, @transmissao, @binario, @Potencia, @CC)"
                    SelectCommand="SELECT DISTINCT Nome, Marca, Preco_Base, Cod_ISV, CC, Potencia, binario, transmissao, consumo FROM Carro WHERE (Cod_Carro = @Cod_Carro)"
                    UpdateCommand="UPDATE Carro SET Marca = @marca, Preco_Base = @preco, Cod_ISV = @isv, CC = @cc, Potencia = @potencia, binario = @binario, transmissao = @transmissao, consumo = @consumo, Nome = @nome">
                    <InsertParameters>
                        <asp:Parameter Name="Cod_Carro" />
                        <asp:Parameter Name="Marca" />
                        <asp:Parameter Name="Preco_Base" />
                        <asp:Parameter Name="Cod_ISV" />
                        <asp:Parameter Name="Nome" />
                        <asp:Parameter Name="consumo" />
                        <asp:Parameter Name="transmissao" />
                        <asp:Parameter Name="binario" />
                        <asp:Parameter Name="Potencia" />
                        <asp:Parameter Name="CC" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:Parameter Name="Cod_Carro" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Cod_Carro" />
                        <asp:Parameter Name="marca" />
                        <asp:Parameter Name="preco" />
                        <asp:Parameter Name="isv" />
                        <asp:Parameter Name="cc" />
                        <asp:Parameter Name="potencia" />
                        <asp:Parameter Name="binario" />
                        <asp:Parameter Name="transmissao" />
                        <asp:Parameter Name="consumo" />
                        <asp:Parameter Name="nome" />
                    </UpdateParameters>
                </asp:SqlDataSource>


Abraços

dicas3d

Share this post


Link to post
Share on other sites
Caça

Essa dropdownlist  está preenchida no momento em que os dados são carregados para a detailsview?


Pedro Martins

Não respondo a duvidas por PM

Share this post


Link to post
Share on other sites
dicas3d

Eis o código da drop:

                                <asp:DropDownList ID="ddlISV" runat="server" AppendDataBoundItems="True"
                                    SelectedValue='<%# Bind("Cod_ISV") %>'>
                                    <asp:ListItem Value="" Text="" />
                                </asp:DropDownList>

Suponho que a drop já deva estar carregada.

Encontrei este exemplo na net(http://www.heroicsalmonleap.net/links/DropDownListInGridViewBoundToDataSource.zip), porem não o consigo por a funcionar no meu caso.


Abraços

dicas3d

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.