[英]set value of textbox from code behind
I'm using asp and have some textboxes where I want to set the value from code behind. 我正在使用asp并有一些文本框,我想从后面的代码中设置值。 The code below is wrapped inside an asp:DetailsView.
下面的代码包装在asp:DetailsView中。
The Textbox I want to get and set value of is InsertItemTemplate with ID=strPositionsName 我要获取并设置值的文本框是ID = strPositionsName的InsertItemTemplate
<asp:TemplateField HeaderText="Name" SortExpression="strPositionName">
<InsertItemTemplate>
<asp:TextBox ID="strPositionName" Width="380px" MaxLength="49" runat="server" Text='<%# Bind("strPositionName") %>'></asp:TextBox>
</InsertItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Textbox1" Width="380px" MaxLength="49" runat="server" Text='<%# Bind("strPositionName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Width="380px" Text='<%# Bind("strPositionName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I managed to get the value by: 我设法通过以下方式获得价值:
var testName = ((TextBox)DetailsView1.FindControl("strPositionName")).Text;
So I tried using this: 所以我试着用这个:
((TextBox)DetailsView1.FindControl("strPositionName")).Text = "textboxvalue";
But it didn't work 但这没用
Try Following Code 尝试以下代码
TextBox _txtPositionName=(TextBox)DetailsView1.FindControl("strPositionName");
if(_txtPositionName!=null)
_txtPositionName.Text="textboxvalue";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.