Не удается найти идентификатор элемента управления в ControlParameter

Я пытаюсь вставить значения из текстового поля, но получаю сообщение об ошибке, что не удается найти controlid в параметре control. TextBox находится внутри формы, внутри списка. SqlDataSource находится вне ListView.

Мой метод InsertButton_Click

protected void InsertButton_Click(object sender, EventArgs e)
    {

        var ctrl = (Control)sender;
        var formview = (FormView)ctrl.NamingContainer;
        formview.ChangeMode(FormViewMode.Insert);
        SectionListView.DataSource = SectionDataSource;
        SectionListView.DataBind();

    }

Шаблон InsertItem

<InsertItemTemplate>
    <tr style="">
        <td>
           <div style="font-size: .8em;">
               <asp:FormView ID="SectionFormView" runat="server" DataKeyNames="SectionItemID" DataSourceID="SectionDataSource">
                   <ItemTemplate>
                       <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" OnClick="InsertButton_Click" Font-Size="1.2em" />
                       <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" Font-Size="1.2em" />
                       <asp:Label ID="SectionItemLabel" runat="server" Text="SectionItem" Font-Bold="true" Font-Size="1.2em" />
                       <asp:TextBox ID="SectionItemTextBox" runat="server" />
                       <asp:Label ID="SectionItemSubLabel" runat="server" Text="SectionItem Label" Font-Bold="true" Font-Size="1.2em" />
                       <asp:TextBox ID="SectionItemLabelTextBox" runat="server"/>

                   </ItemTemplate>
               </asp:FormView>
           </div>
      </td>
  </tr>
</InsertItemTemplate>

Мой SqlDataSource

<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
                    InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (@SectionItem, @SectionItemLabel)">
        <InsertParameters>
                <asp:ControlParameter ControlID="SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
                <asp:ControlParameter ControlID="SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
        </InsertParameters>
 </asp:SqlDataSource>

1 ответ

Решение

Если вы хотите использовать дочерние элементы управления в качестве параметров элемента управления, вы должны использовать квалифицированный идентификатор в качестве идентификатора элемента управления. Попробуйте изменить источник данных SQL, как показано ниже

<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
                    InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (@SectionItem, @SectionItemLabel)">
        <InsertParameters>
                <asp:ControlParameter ControlID="SectionFormView$SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
                <asp:ControlParameter ControlID="SectionFormView$SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
        </InsertParameters>
 </asp:SqlDataSource>
Другие вопросы по тегам