重新加载asp.net详细信息视图中的下拉框

时间:2015-08-13 14:42:27

标签: asp.net vb.net detailsview templatefield

在详情视图中,我有一个下拉列表,其选择决定了第二个下拉列表中的列表。当网页加载我的所有"获取数据"函数加载各种下拉框。在我在两个相关下拉框的第一个中做出选择后,我调用了一个"索引已更改"将第一个下拉框的值作为变量获取的函数,并将其放入SQL语句中。此SQL语句在SQL中正确运行。但是,第二次下拉不会使用新数据重新加载第二次下拉中的值保持不变。以下是相关代码:

` <asp:TemplateField HeaderText="Planting Hatchery">
    <ItemTemplate>
        <asp:Label ID="lblPlantHatch" runat="server" Text='<%# Eval  ("HatcheryCodePlant")%>' Visible = "true"></asp:Label>
   </ItemTemplate>
   <insertItemTemplate>
        <asp:DropDownList ID="ddPlantingHatchery" runat="server" DataSource='<%# GetPlantingHatchery()%>'DataTextField="HatcheryNamePlant" DataValueField="HatcheryCodePlant" width= "150" AppendDataBoundItems="true" AutoPostBack="true"
OnSelectedIndexChanged="ddPlantingHatchery_indexchanged"> 
  <asp:ListItem Text="Select" Value="" />
     </asp:DropDownList>
  </insertItemTemplate>
 </asp:TemplateField>

<asp:TemplateField HeaderText="Water Body Name">
  <ItemTemplate>
     <asp:Label ID="lblStreamName" runat="server" Text='<%# Eval("CatalogNo")%>' Visible = "true"></asp:Label>
  </ItemTemplate>
  <insertItemTemplate>
    <asp:DropDownList ID="ddCatalogName" runat="server" DataSource='<%#  GetCatalogNames()%>' 
    DataTextField="StreamName" DataValueField="CatalogNo" AppendDataBoundItems="true" > 
    <asp:ListItem Text="Select" Value="" />
       </asp:DropDownList>
          <asp:ObjectDataSource ID="dsWaterBody" runat="server" TypeName="StreamName"
        <SelectMethod="GetCatalogNames">
           <SelectParameters>
             <asp:ControlParameter Name="HatcheryCodePlant" Type="string" ControlID="ddPlantingHatchery" PropertyName="Selectedvalue"/>
           </SelectParameters>
              </asp:ObjectDataSource>
          </insertItemTemplate>`

这是守则背后:`
 公共函数GetPlantingHatchery()As DataSet

    Dim myConnection As New SqlConnection(ConnectionString)

    Dim ad As New SqlDataAdapter("SELECT HatcheryNamePlant, HatcheryCodePlant FROM HatcheryPlant Order by HatcheryNamePlant", myConnection)

    Dim ds As New DataSet()

    ad.Fill(ds, "HatcheryPlant")

    Return ds
End Function

Public Function GetCatalogNames() As DataSet
           Dim myConnection As New SqlConnection(ConnectionString)
    Dim ad As New SqlDataAdapter("SELECT StreamName, CatalogNo, HatcheryNamePlant, HatcheryCodePlant, LLID FROM vwStockingWatersByHatchery Order By StreamName", myConnection)
    Dim dsWaterBody As New DataSet()
    ad.Fill(dsWaterBody, "Catalog")
    Return dsWaterBody

End Function

Public Function ddPlantingHatchery_indexchanged(sender As Object, e As EventArgs)
   Try
        Dim ddCatNum As DropDownList = TryCast(dvSMasterCurrentYear.FindControl("ddCatalogName"), DropDownList)
        'ddCatNum.SelectedValue = TryCast(dvSMasterCurrentYear.FindControl("ddPlantingHatchery"), DropDownList).SelectedValue
        MySelectedValue = TryCast(dvSMasterCurrentYear.FindControl("ddPlantingHatchery"), DropDownList).SelectedValue
        Dim myConnection As New SqlConnection(ConnectionString)
        Dim ad As New SqlDataAdapter("SELECT StreamName, CatalogNo, HatcheryNamePlant, HatcheryCodePlant, LLID FROM vwStockingWatersByHatchery where HatcheryCodePlant = '" + MySelectedValue + "' Order By StreamName", myConnection)
        Dim dsWaterBody As New DataSet()
        ad.Fill(dsWaterBody, "Catalog")
        Return dsWaterBody
    Catch ex As Exception
    End Try`

如何使用新数据加载第二个下拉列表,我需要做什么?

0 个答案:

没有答案