Hello,

I'm working on a small web app in C#, I have made the database and created a gridview to display and edit the data.

I just want to know how can I turn a textbox field (in the update view) to textarea so I can see the whole text before updating.

Thanks.

Dani AI

Generated

Short answer: convert the BoundField into a TemplateField and put an ASP.NET TextBox with TextMode="MultiLine" inside the EditItemTemplate. Use Bind("FieldName") for two-way binding so a data source control can update automatically, or read the control in RowUpdating when you handle updates manually. Since marked this solved, the example below shows a common, robust approach.

Example TemplateField (ASPX):

<asp:TemplateField HeaderText="Notes">
  <ItemTemplate>
    <%# Eval("Notes") %>
  </ItemTemplate>
  <EditItemTemplate>
    <asp:TextBox ID="txtNotes" runat="server"
      Text='<%# Bind("Notes") %>'
      TextMode="MultiLine" Rows="6" Columns="60"
      CssClass="gv-textarea" />
  </EditItemTemplate>
</asp:TemplateField>

If you update the row in code-behind (manual update), find the control in RowUpdating:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = GridView1.Rows[e.RowIndex];
    TextBox txt = (TextBox)row.FindControl("txtNotes");
    string newValue = txt?.Text ?? String.Empty;
    // set e.NewValues["Notes"] = newValue; or update DB directly
}

Troubleshooting and tips: use Visual Studio -> Edit Columns to switch a BoundField to a TemplateField; set DataKeyNames on the GridView so updates can identify the row; if using SqlDataSource/ObjectDataSource, Bind in EditItemTemplate lets the framework handle updates automatically. Control sizing is best handled with CSS (set width/height) rather than huge Columns. Watch encoding: display HTML-encoded content safely and decode only when needed for editing to avoid XSS.

Edit: Solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.