【问题标题】:Getting textbox value inside a Detailsview control在 Detailsview 控件中获取文本框值
【发布时间】:2011-07-14 11:32:38
【问题描述】:

我有一个带有模板字段的 DetailsView 控件,如下所示:

<asp:TemplateField SortExpression="Title">
  <ItemTemplate>
    <asp:TextBox ID="txtMessageTitle" Text='<%# Bind("Title") %>' runat="server">
    </asp:TextBox>
    <asp:Button ID="btnUpdateTitle" runat="server" Text="Update" 
      CommandName="UpdateTitle" CommandArgument='<%# Bind("MessageID") %>' oncommand="btnUpdateCommand"/>
  </ItemTemplate>
</asp:TemplateField>  

详细信息视图包含在 UpdatePanel 中。

当用户单击btnUpdateButton 时,我希望能够在后面的代码中检索文本框 (txtMessageTitle) 值,并使用按钮的 CommandArgument 更新数据库中的相应 MessageTitle。如何从按钮的 Command 事件中检索 DetailsView 控件中的文本框值? 谢谢。

【问题讨论】:

    标签: asp.net .net-3.5 detailsview nested-controls


    【解决方案1】:

    使用以下内容:

       TextBox txtMessageTitle = detailsViewName.FindControl("txtMessageTitle") as TextBox;
       string text = txtMessageTitle.Text;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多