代码后面的Databind()永远不会到达数据库

问题描述 投票:0回答:1

我的 FormView 不会进行数据绑定。我没有收到任何错误,所有元素都正确找到,当我单步执行代码时,一切看起来都按预期工作。 select 参数已设置,FormView 已进行 DataBound。

但是没有返回任何数据,并且我的数据库日志记录显示从未触及过要进行 DataBound 的过程。

更新面板

 <asp:updatepanel ID="upnlMixingTankInfo" runat="server">
<ContentTemplate>
 <asp:formview id="fvMixingTankInfo" runat="server" datasourceid="SqlDataSourceMixingTankInfo">
   <ItemTemplate>
         <asp:label runat="server">Vessel Capacity:</asp:label>
         <asp:TextBox ID="vesselCapacity" runat="server" class="form-control" Text='<%# Bind("fldVesselCapacity")%>'></asp:TextBox>
   </ItemTemplate>
  </asp:formview>
</ContentTemplate>

背后代码:

SourceDropDownList = sender
  upnlMixingTankInfo = CType(SourceDropDownList.Parent.FindControl("upnlMixingTankInfo"), UpdatePanel)
        fvTankInfo = CTYPE(upnlMixingTankInfo.FindControl("fvMixingTankInfo"), FormView)
        If Not IsNothing(SourceDropDownList.SelectedValue) Then
           SqlDataSourceMixingTankInfo.SelectParameters.Add("TankName", DropDownListEquipmentList.SelectedValue)
        End If
        fvTankInfo.Databind()

SQL数据源:

         <asp:SqlDataSource ID="SqlDataSourceMixingTankInfo" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ZMConnectionString %>"   
    SelectCommand="EXEC stpWebGetMixTankCapacity @TankName" >
    <SelectParameters>
      <asp:Parameter Name="TankName" defaultvalue=""/>
    </SelectParameters>

c# asp.net .net vb.net sqldatasource
1个回答
2
投票

SqlDataSource 中的改动很少,就完成了,我已经使用自己的 sp 进行了测试,根据您的使用情况进行修改。

更新面板和表单视图

<asp:UpdatePanel ID="upnlMixingTankInfo" runat="server">
    <ContentTemplate>
        <asp:FormView ID="fvMixingTankInfo" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server">Vessel Capacity:</asp:Label>
                <asp:TextBox ID="vesselCapacity" runat="server" class="form-control" Text='<%# Bind("Name")%>'></asp:TextBox>
            </ItemTemplate>
        </asp:FormView>
    </ContentTemplate>
</asp:UpdatePanel>

代码隐藏,我已经在负载上进行了测试,您可以在任何地方使用相同的代码。

    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.SelectParameters.Add("Id", "10");
    }

SqlDataSource 发生变化:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="GetImages" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

它工作得很好,我在提交之前已经测试过。

© www.soinside.com 2019 - 2024. All rights reserved.