简体   繁体   English

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

[英]Databind() from code behind never reaches the database

My FormView wont DataBind. 我的FormView不会使用DataBind。 I get no errors, all the elements are found correctly, when I step through the code everything looks like it works as expecting. 我没有错误,所有元素都正确找到,当我逐步执行代码时,一切看起来都按预期工作。 The select parameter is set and the FormView is DataBound. 设置选择参数,并且FormView为DataBound。

But no data is returned and my database logging shows that the procedure that is meant to be DataBound is never touched. 但是没有返回任何数据,并且我的数据库日志记录表明,从未触及到是DataBound的过程。

Update Panel 更新面板

 <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>

Code Behind: 背后的代码:

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()

SQLDATSOURCE: SQLDATSOURCE:

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

Few changes in SqlDataSource and done, I've tested using my own sp, modify it according to your usage. 我已经使用自己的sp测试了SqlDataSource中的少量更改并完成了更改,请根据您的用法进行修改。

UpdatePanel & FormView UpdatePanel和FormView

<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>

Code Behind, I've tested on load, you can use same code wherever you want. 代码背后,我已经对负载进行了测试,您可以在任何地方使用相同的代码。

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

SqlDataSource with changes: SqlDataSource的更改:

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

It works perfectly, I've tested before submitting here. 效果很好,我在提交之前已经过测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM