首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在ControlParameter中找到控制ID

无法在ControlParameter中找到控制ID
EN

Stack Overflow用户
提问于 2014-08-19 14:29:38
回答 1查看 4.8K关注 0票数 2

我正在尝试从文本框中插入值,但是我得到了一个错误,即它无法在控制参数中找到该控件。TextBox在一个表单视图中,这个表单视图在一个列表视图中。SqlDataSource在ListView之外。

我的InsertButton_Click方法

代码语言:javascript
复制
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模板

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-19 14:51:29

如果要将子控件用作控件参数,则需要使用限定id作为控件id。尝试更改SQL数据源,如下所示

代码语言:javascript
复制
<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>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25386048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档