cascadierende DropDownList an DataList übergeben

Lothar Rappsilber 1 Reputation point
2021-11-01T14:50:27.763+00:00

Hallo,

ich habe eine kaskadierende DropDownList, die funktioniert (Land, Bundesland, Region). Ich möchte das Ergebnis der Region in DataList ausgeben, aber es gelingt mir leider nicht. War mache ich falsch? Mein Code:

                     <asp:TemplateField>  
                     <ItemTemplate>  
                     <asp:DataList ID="DataListName" runat="server" Text='<%# Eval("Name") %>'>  
                     </asp:DataList>  
                     </ItemTemplate>  
                     </asp:TemplateField>  

und danach:

Protected Sub idRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As [String] = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim strQuery As [String] = "Select * from Campingplatz where idLand =@LandID and idBundesland = @BundeslandID and idRegion = @RegionID ORDER BY Name ASC"
Dim con As New MySqlConnection(strConnString)
Dim cmd As New MySqlCommand()
cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
cmd.Parameters.AddWithValue("@BundeslandID", MySqlDbType.Decimal).Value = DropDownBundesland.SelectedItem.Value
cmd.Parameters.AddWithValue("@RegionID", MySqlDbType.Decimal).Value = DropDownRegion.SelectedItem.Value
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DataListName.DataSource = cmd.ExecuteReader()
DataListName.DataBind()
Catch ex As Exception
'Throw ex
Finally
con.Close()
con.Dispose()
End Try
End Sub

Wer kann mir helfen?145347-dropdownlist1.jpg

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,641 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Lothar Rappsilber 1 Reputation point
    2021-11-05T13:14:12.217+00:00

    Wenn ich DataListName.DataBind() eingebe:

    Protected Sub idRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim strConnString As [String] = ConfigurationManager.ConnectionStrings("conString").ConnectionString
        Dim strQuery As [String] = "Select * from Campingplatz where idLand =@LandID and idBundesland = @BundeslandID and idRegion = @RegionID ORDER BY Name ASC"
        Dim con As New MySqlConnection(strConnString)
        Dim cmd As New MySqlCommand()
        cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
        cmd.Parameters.AddWithValue("@BundeslandID", MySqlDbType.Decimal).Value = DropDownBundesland.SelectedItem.Value
        cmd.Parameters.AddWithValue("@RegionID", MySqlDbType.Decimal).Value = DropDownRegion.SelectedItem.Value
        cmd.CommandType = CommandType.Text
        cmd.CommandText = strQuery
        cmd.Connection = con
        Try
            con.Open()
            DataListName.DataSource = cmd.ExecuteReader()
            **DataListName.DataBind()**
        Catch ex As Exception
            'Throw ex
        Finally
                con.Close()
                con.Dispose()
            End Try
    End Sub
    

    macht er mir die Tabelle kaputt. Wie verhindere ich das?

    0 comments No comments