如何解决尝试在FormView中设置TextBox1的默认值
使用C#和WebForms的ASP.Net
我只是想在页面加载时在FormView内用认可值填充TextBox。 FormView的默认模式为“编辑”,它将仅保留在“编辑”中。我需要一些有效的代码和语法。我已经尝试过,但是无法填充该字段。我包括FormView标记和背后的代码。我感谢任何可以提供帮助的人。我知道这可能很简单,但是我遇到了各种各样的麻烦,但没有发现任何有效的方法。
我遇到的大多数解决方案都是针对插入的。
FormView1标记
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="test_default" DefaultMode="Edit" AllowPaging="True" >
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" BackColor="#FFFFCC" Height="35px" Width="200px"></asp:TextBox>
<br />
id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
<br />
status:
隐藏代码
protected void Page_Load(object sender,EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
TextBox TextBox2 = FormView1.FindControl("TextBox2") as TextBox;
if (TextBox2 != null)
{
TextBox2.Text = "approved";
}
解决方法
这行得通!
protected void Page_PreInit(object sender,EventArgs e)
{
if (submitted_to_email != null)
{
_ = Context.User.Identity.Name;
if (User.Identity.IsAuthenticated)
submitted_to_email.Text = User.Identity.Name;
}
if (TextBox1 != null)
{
TextBox1.Text = "approved";
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。