У меня есть два Formview на одной странице. Я могу использовать FindControl на первом без проблем, но на втором он всегда терпит неудачу.
Я использую ItemTemplate для обоих, оба по умолчанию для ReadOnly, оба привязаны к SQLDataSources (разным), но я не могу понять, почему FindControl работает для одного, а не для другого.
Я удалил много простого текста из кода ниже.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Apps] WHERE ([AppID] = @AppID)" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="AppID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<h1>
<asp:Label ID="AppNameLabel" runat="server" Text='<%# Bind("AppName") %>' />
<asp:Label ID="VersionLabel" runat="server" Text='<%# Bind("Version") %>' /> for
<asp:Label ID="OSLabel" runat="server" Text='<%# Bind("OS") %>' />
</h1>
<p>Text here</p>
<p><asp:TextBox ID="LicenseTextBox" runat="server"
Text='<%# Eval("License")%>'
TextMode="MultiLine" Width="800px" Rows="25" ReadOnly="True"></asp:TextBox></p>
<asp:HiddenField ID="AppLocation" runat="server" ViewStateMode="Inherit" Value='<%# Bind("AppLocation") %>'/>
</ItemTemplate>
</asp:FormView>
<p><asp:Literal ID="SizeLiteral" runat="server"></asp:Literal></p>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Installations] WHERE (([AppID] = @AppID) AND ([Username] = @Username))" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
<asp:FormParameter FormField="Username" Name="Username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="DLFormView" runat="server" DataSourceID="SqlDataSource4"
DataKeyNames="AppID,Username">
<ItemTemplate>
<p> <asp:Label ID="DLAppNameLabel" runat="server" />
<br />
<br />
<asp:Label ID="NumberOfInstallations" runat="server" Text='<%# Bind("Installations") %>'></asp:Label>
<br />
<asp:HiddenField ID="TotalInstallations" runat="server" />
Number of New Installations:
<asp:DropDownList ID="NumberOfNewInstallations" runat="server">
</asp:DropDownList>
<br />
<asp:Label ID="TotalNumberOfInstallations" runat="server" Text="Label"></asp:Label>
</p>
</ItemTemplate>
</asp:FormView>
И кодировка FindControl выглядит следующим образом...
TextBox LicTextBox = (TextBox)FormView1.FindControl("LicenseTextBox");
HiddenField AppLocCode = (HiddenField)FormView1.FindControl("AppLocation");
Label AppNameCode = (Label)FormView1.FindControl("AppNameLabel");
Эти всегда работают...
Label DLAppNameCode = (Label)DLFormView.FindControl("DLAppNameLabel");
Это всегда возвращает ноль. Я прочитал миллион сообщений о том, что элементы управления не отображаются до тех пор, пока не завершится привязка данных, но, безусловно, если два FORmView настроены одинаково, результат должен быть одинаковым.
Любая помощь будет высоко оценена :)
Мэтт :)
TextBox LicTextBox = (TextBox)FormView1.FindControl("LicenseTextBox");
, отладчик переходит на страницу aspx и просматривает все поля asp в FormView1. Когда я достигаюLabel DLAppNameCode = (Label)DLFormView.FindControl("DLAppNameLabel");
, код не переходит на страницу aspx, поэтому не ищет никаких элементов управления asp. Кто-нибудь знает, почему? - person Matty W   schedule 27.02.2012