Ciao a tutti, ho un fomr dal quale devo aggiornare dei dati, quando provo a fare il binding ottengo il seguente errore:
"SelectedValue in 'DrpTipoAffiliato' non valido, poiché non è incluso nell'elenco di elementi.
Nome parametro: value "
Sotto posto il codice del from, e il codie in VB. Grazie a chiunque volesse darmi una mano.
<asp:ListView ID="ListView1"
runat="server"
DataKeyNames="IdEsapoint"
DataSourceID="EPSource" >
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat ="server">
<table id="itemplaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF; border-collapse: collapse;
border-color: #999999; border-bottom-style: none; border-width: 1px;
font-family: 'Times New Roman', Verdana, Helvetica, sans-serif">
<tr runat="server" id="Intestazione1" style="background-color: black; color: white">
<th id="Th0" runat="server">Edit</th>
<th id="Th1" runat="server">IDEsaPoint</th>
<th id="Th2" runat="server">IdAffiliato</th>
<th id="Th3" runat="server">TipoAffiliato</th>
<th id="Th4" runat="server">RagioneSociale</th>
<th id="Th5" runat="server">DataAffiloiazione</th>
<th id="Th6" runat="server">Responsabile</th>
<th id="Th7" runat="server">Indirizzo</th>
<th id="Th8" runat="server">Località</th>
<th id="Th9" runat="server">Cap</th>
<th id="Th10" runat="server">Provincia</th>
<th id="Th11" runat="server">Stato</th>
<th id="Th12" runat="server">Email</th>
<th id="Th13" runat="server">Telefono</th>
<th id="Th14" runat="server">Fax</th>
<th id="Th15" runat="server">Cellulare</th>
<th id="Th16" runat="server">PIva</th>
</tr>
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="background-color: #DCDCDC; color: #000000">
<td>
<asp:Button ID="EditButton"
runat="server"
Text="Edit"
CommandName="Aggiorna"
CommandArgument='<%# Eval("IDEsaPoint")%>'
OnCommand="EditButton_Command" />
</td>
<td>
<asp:Label ID="LblIDEsaPoint" runat="server"
Text='<%# Eval("IDEsaPoint")%>'/>
</td>
<td>
<asp:Label ID="LblIdAffiliato" runat="server"
SelectedValue='<%# Eval("IdAffiliato")%>'/>
</td>
<td>
<asp:Label ID="LblTipoAffliato" runat="server"
SelectedValue='<%# Eval("TipoAffiliato")%>'/>
</td>
<td>
<asp:Label ID="LblRagioneSociale" runat="server"
Text='<%# Eval("RagioneSociale")%>'/>
</td>
<td>
<asp:Label ID="LblDataAffiliazione" runat="server"
Text='<%# Eval("DataAffiliazione")%>'/>
</td>
<td>
<asp:label ID="LblResponsabile" runat="server"
Text='<%# Eval("Responsabile")%>'/>
</td>
<td>
<asp:Label ID="LblIndirizzo" runat="server"
Text='<%# Eval("Indirizzo")%>' />
</td>
<td>
<asp:Label ID="LblLocalità" runat="server"
Text='<%# Eval("Località")%>' />
</td>
<td>
<asp:Label ID="LblCap" runat="server"
Text='<%# Eval("Cap")%>'/>
</td>
<td>
<asp:Label ID="LblProvincia" runat="server"
Text='<%# Eval("Provincia")%>'/>
</td>
<td>
<asp:Label ID="LblStato" runat="server"
Text='<%# Eval("Stato")%>'/>
</td>
<td>
<asp:Label ID="LblEmail" runat="server"
Text='<%#Eval("Email")%>'/>
</td>
<td>
<asp:Label ID="LblTelefono" runat="server"
Text='<%# Eval("Telefono")%>'/>
</td>
<td>
<asp:Label ID="LblFax" runat="server"
Text='<%# Eval("FAx")%>'/>
</td>
<td>
<asp:Label ID="LblCellulare" runat="server"
Text='<%# Eval("Cellulare")%>'/>
</td>
<td>
<asp:Label ID="LblPIva" runat="server"
Text='<%# Eval("PIva") %>'/>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr id="Tr2" runat="server" style="background-color: #008A8C; color:#FFFFFF">
<td>
<asp:Button ID="Btnedit" runat="server"
commandName="Update"
Text="Update"/>
</td>
<td>
<asp:Label ID="LblIDEsaPoint" runat="server"
Text='<%# Eval("IDEsaPoint")%>'/>
</td>
<td>
<asp:DropDownList ID="DrpIdAffiliati" runat="server"
SelectedValue='<%# Bind("IdAffiliato")%>'
/>
</td>
<td>
<asp:DropDownList ID="DrpTipoAffliato" runat="server"
SelectedValue='<%# Bind("TipoAffiliato")%>'
/>
</td>
<td>
<asp:TextBox ID="TxtRagioneSociale" runat="server"
Text='<%# Bind("RagioneSociale")%>'/>
</td>
<td>
<asp:TextBox ID="TxtDataAff" runat="server"
Text='<%# Bind("DataAffiliazione")%>'/>
</td>
<td>
<asp:TextBox ID="TxtRes" runat="server"
Text='<%# Bind("Responsabile")%>'/>
</td>
<td>
<asp:TextBox ID="TxtIndirizzo" runat="server"
Text='<%# Bind("Indirizzo")%>' />
</td>
<td>
<asp:TextBox ID="TxtLocalità" runat="server"
Text='<%# Bind("Località")%>' />
</td>
<td>
<asp:TextBox ID="TxtCap" runat="server"
Text='<%# Bind("Cap")%>'/>
</td>
<td>
<asp:TextBox ID="TxtProvincia" runat="server"
Text='<%# Bind("Provincia")%>'/>
</td>
<td>
<asp:TextBox ID="TxtStato" runat="server"
Text='<%# Bind("Stato")%>'/>
</td>
<td>
<asp:TextBox ID="TxtEmail" runat="server"
Text='<%#Bind("Email")%>'/>
</td>
<td>
<asp:TextBox ID="TxtTel" runat="server"
Text='<%# Bind("Telefono")%>'/>
</td>
<td>
<asp:TextBox ID="TxtFax" runat="server"
Text='<%# Bind("FAx")%>'/>
</td>
<td>
<asp:TextBox ID="TxtCel" runat="server"
Text='<%# Bind("Cellulare")%>'/>
</td>
<td>
<asp:TextBox ID="TxtPIva" runat="server"
Text='<%# Bind("PIva")%>'/>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="EPSource"
runat="server"
ConnectionString="<%$ ConnectionStrings:EsaWebConnectionString %>"
SelectCommand="SELECT * FROM [T_EsaPoint]"
UpdateCommand ="Update [IdEsaPoint] SET [IdAffiliato] = @IdAffiliato,
[TipoAffiliato] = @TipoAffiliato, [RagioneSociale] = @RagioneSociale,
[DataAffiliazione] = @DataAffiliazione, [Responsabile] = @Responsabile,
[Indirizzo] = @Indirizzo, [Località] = @Località, [Cap] = @Cap,
[Provincia] = @Provincia, [Stato] = @Stato, [Email] = @Email,
[Telefono] = @Telefono, [Fax] = @Fax, [Cellulare] = @Cellulare,
[PIva] = @PIva">
<UpdateParameters>
<asp:Parameter Type="Int32" Name="IDEsaPoint" />
<asp:Parameter Type="Int32" Name="IdAffiliato" />
<asp:Parameter Type="String" Name="TipoAffiliato" />
<asp:Parameter Type="String" Name="RagioneSociale" />
<asp:Parameter Type="DateTime" Name="DataAffiliazione" />
<asp:Parameter Type="String" Name="Responsabile" />
<asp:Parameter Type="String" Name="Indirizzo" />
<asp:Parameter Type="String" Name="Località" />
<asp:Parameter Type="String" Name="Cap" />
<asp:Parameter Type="String" Name="Provincia" />
<asp:Parameter Type="String" Name="Stato" />
<asp:Parameter Type="String" Name="Email" />
<asp:Parameter Type="String" Name="Telefono" />
<asp:Parameter Type="String" Name="Fax" />
<asp:Parameter Type="String" Name="Cellulare" />
<asp:Parameter Type="String" Name="PIva" />
</UpdateParameters>
</asp:SqlDataSource>
CODICE VB
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class NewEsaPoint
Inherits System.Web.UI.Page
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mode As String = Request.QueryString("mode")
Dim IDEsaPoint As String = Request.QueryString("IDEsaPoint")
Select mode
Case "Modifica"
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ConnectionString)
Dim cmd As New SqlCommand("select * from T_EsaPoint where IDEsaPoint = @IDEsaPoint", conn)
cmd.Parameters.Add("@IDEsaPoint", SqlDbType.Int).Value = IDEsaPoint
conn.Open()
Dim rs As SqlDataReader = cmd.ExecuteReader
If rs.HasRows Then
rs.Read()
TxtIDEsapoint.Text = rs("IDEsaPoint").ToString()
DrpIdaffiliati.SelectedValue = rs("IdAffiliato").ToString
DrpTipoAffiliato.SelectedValue = rs("TipoAffiliato").ToString()
TxtRagioneSociale.Text = rs("RagioneSociale").ToString()
TxtDataAff.Text = rs("DataAffiliazione").ToString()
TxtResp.Text = rs("Responsabile").ToString()
Txtindirizzo.Text = rs("Indirizzo").ToString()
TxtLocalità.Text = rs("Località").ToString()
TxtCap.Text = rs("Cap").ToString()
TxtProvincia.Text = rs("Provincia").ToString()
TxtStato.Text = rs("Stato").ToString()
TxtEmail.Text = rs("Email").ToString()
TxtTel.Text = rs("Telefono").ToString()
TxtFax.Text = rs("Fax").ToString()
TxtCel.Text = rs("Cellulare").ToString()
TxtPIva.Text = rs("PIva").ToString()
End If
rs.Close()
conn.Close()
End Using
End Select
End Sub
Protected Sub BtnSalva_Click(sender As Object, e As EventArgs) Handles BtnSalva.Click
Dim CmdIns As SqlCommand
Dim StrIns As String
Dim DataAffiliazione As Date
StrIns = "Insert T_EsaPoint ("
StrIns = StrIns & "IdAffiliato"
StrIns = StrIns & ", TipoAffiliato"
StrIns = StrIns & ",RagioneSociale"
StrIns = StrIns & ",DataAffiliazione"
StrIns = StrIns & ",Responsabile"
StrIns = StrIns & ",Indirizzo"
StrIns = StrIns & ",Località"
StrIns = StrIns & ",Cap"
StrIns = StrIns & ",Provincia"
StrIns = StrIns & ",Stato"
StrIns = StrIns & ",Email"
StrIns = StrIns & ",Telefono"
StrIns = StrIns & ",Fax"
StrIns = StrIns & ",Cellulare"
StrIns = StrIns & ",PIva"
StrIns = StrIns & ")VALUES("
StrIns = StrIns & "@IdAffiliato"
StrIns = StrIns & ",@TipoAffiliato"
StrIns = StrIns & ",@RagioneSociale"
StrIns = StrIns & ",@DataAffiliazione"
StrIns = StrIns & ",@Responsabile"
StrIns = StrIns & ",@Indirizzo"
StrIns = StrIns & ",@Località"
StrIns = StrIns & ",@Cap"
StrIns = StrIns & ",@Provincia"
StrIns = StrIns & ",@Stato"
StrIns = StrIns & ",@Email"
StrIns = StrIns & ",@Telefono"
StrIns = StrIns & ",@Fax"
StrIns = StrIns & ",@Cellulare"
StrIns = StrIns & ",@PIva"
StrIns = StrIns & ")"
CmdIns = New SqlCommand(StrIns, conn)
CmdIns.Parameters.Add("IdAffiliato", SqlDbType.Int).Value = DrpIdaffiliati.Text
CmdIns.Parameters.Add("TipoAffiliato", SqlDbType.VarChar).Value = DrpTipoAffiliato.Text
CmdIns.Parameters.Add("RagioneSociale", SqlDbType.VarChar).Value = TxtRagioneSociale.Text
CmdIns.Parameters.Add("DataAffiliazione", SqlDbType.Date).Value =
If(DateTime.TryParse(TxtDataAff.Text, DataAffiliazione), DataAffiliazione, DBNull.Value)
CmdIns.Parameters.Add("Responsabile", SqlDbType.VarChar).Value = TxtResp.Text
CmdIns.Parameters.Add("Indirizzo", SqlDbType.VarChar).Value = Txtindirizzo.Text
CmdIns.Parameters.Add("Località", SqlDbType.VarChar).Value = TxtLocalità.Text
CmdIns.Parameters.Add("Cap", SqlDbType.VarChar).Value = TxtCap.Text
CmdIns.Parameters.Add("Provincia", SqlDbType.VarChar).Value = TxtProvincia.Text
CmdIns.Parameters.Add("Stato", SqlDbType.VarChar).Value = TxtStato.Text
CmdIns.Parameters.Add("Email", SqlDbType.VarChar).Value = TxtEmail.Text
CmdIns.Parameters.Add("Telefono", SqlDbType.VarChar).Value = TxtTel.Text
CmdIns.Parameters.Add("Fax", SqlDbType.VarChar).Value = TxtFax.Text
CmdIns.Parameters.Add("Cellulare", SqlDbType.VarChar).Value = TxtCel.Text
CmdIns.Parameters.Add("PIva", SqlDbType.VarChar).Value = TxtPIva.Text
conn.Open()
CmdIns.ExecuteNonQuery()
conn.Close()
Response.Redirect("NewEsaPoint.aspx")
End Sub
Protected Sub EditButton_Command(sender As Object, e As CommandEventArgs)
Response.Redirect("NewEsapoint.aspx?mode=Modifica&iDEsaPoint=" & e.CommandArgument)
End Sub
Protected Sub BtnMenu2_Click(sender As Object, e As EventArgs) Handles BtnMenu2.Click
BtnHome2.Visible = True
End Sub
Protected Sub BtnHome2_Click(sender As Object, e As EventArgs) Handles BtnHome2.Click
Response.Redirect("AppEw.aspx")
End Sub
Protected Sub DrpIdaffililiati_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DrpIdaffiliati.SelectedIndexChanged
DrpDescrizioneAff.SelectedValue = DrpIdaffiliati.SelectedValue
DrpTipoAffiliato.SelectedValue = DrpIdaffiliati.SelectedValue
DrpIdaffiliati.SelectedValue = DrpDescrizioneAff.SelectedValue
End Sub
Protected Sub DrpDescrizioneAff_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DrpDescrizioneAff.SelectedIndexChanged
DrpIdaffiliati.SelectedValue = DrpDescrizioneAff.SelectedValue
DrpTipoAffiliato.SelectedValue = DrpDescrizioneAff.SelectedValue
End Sub
Protected Sub DrpTipoAffiliato_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DrpTipoAffiliato.SelectedIndexChanged
DrpIdaffiliati.SelectedValue = DrpTipoAffiliato.SelectedValue
DrpDescrizioneAff.SelectedValue = DrpTipoAffiliato.SelectedValue
End Sub
End Class