Hi
I have written below code in Gridview . I want to set Dafault value = "".
When i write this - e.Row.Cells[e.Row.Cells.Count - 1].Text = ""; it make it as readable
C#
TextBox txtDate = new TextBox();
txtDate.CssClass = "form-control";
txtDate.DataBind();
e.Row.Cells[e.Row.Cells.Count - 1].Controls.Add(txtDate);Thanks

Tuhin PaulRank #7 · 71.9K reputationPosted May 5, 2023, 5:04 AM EDT
To set the default value of the `TextBox` control to an empty string ("") in the `GridView`, you can use the `Text` property of the `TextBox` control. You can set the `Text` property of the `TextBox` control to an empty string in the `RowDataBound` event handler of the `GridView`. In this example, the `Text` property of the `TextBox` control is set to an empty string in the `RowDataBound` event handler. This will set the default value of the `TextBox` control to an empty string for each row in the `GridView`.
protected void gr_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtDate = new TextBox(); txtDate.CssClass = "form-control"; txtDate.Text = ""; // Set default value to an empty string e.Row.Cells[e.Row.Cells.Count - 1].Controls.Add(txtDate); } }