Hi ramco1917,
Please refer below sample.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
</asp:GridView>
Namespace
C#
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BoundField bfield = new BoundField();
bfield.HeaderText = "Name";
bfield.DataField = "Name";
GridView1.Columns.Add(bfield);
TemplateField tfield = new TemplateField();
tfield.HeaderText = "Country";
GridView1.Columns.Add(tfield);
}
this.BindGrid();
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("DOB",typeof(DateTime)) });
dt.Rows.Add(1, "John Hammond", "2023-04-01");
dt.Rows.Add(2, "Mudassar Khan", "2023-04-01");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtDOB = new TextBox();
txtDOB.ID = "txtDOB";
txtDOB.Text = (e.Row.DataItem as DataRowView).Row["DOB"].ToString();
e.Row.Cells[1].Controls.Add(txtDOB);
}
}
Screenshot