<div class="votecell post-layout--left"> <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="64526565"> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0">ASP.Net
using C# and WebForms--- I am simply trying to populate a TextBox within a FormView with a value of approved when the page loads. The FormView's DEFAULT MODE is Edit and it will remain in Edit only. I am in need of some code and syntax that works. I have tried
but I cant get the field to populate. I'm including the FormView markup and the Code Behind. I appreciate anyone that can help with this. I know it may be simply but I have had all kinds of trouble with it..not really finding anything that works. Most of the
solutions I have come across are for Inserting.</div> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0">
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";
}
}
}
Best regards,
Yijing Sun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
4 Posts
Set Default Value TextBox2 inside FormView
Oct 25, 2020 05:16 PM|webdesignernotcoder|LINK
</div> </div> </div>
Contributor
3430 Points
1302 Posts
Re: Set Default Value TextBox2 inside FormView
Oct 26, 2020 02:05 AM|yij sun|LINK
Hi webdesignernotcoder,
Accroding to your description and codes,I have created a test and it's working fine.
Do you have bind the datasource to formview?You don't related to DataSource.
I created a demo,just like this:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSource1" 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 /> </EditItemTemplate> </asp:FormView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnet-TestApplicationWithDatabase-20190820030542 %>" SelectCommand="SELECT * FROM [Test]"></asp:SqlDataSource>
Code-behind:
Best regards,
Yijing Sun