Hey akhter,
Please refer below sample.
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvCustomers_OnRowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Date" HeaderText="Date" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtHoures" runat="server" Text='<%#Eval("Hours") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name", typeof(string)), new DataColumn("Date", typeof(string)), new DataColumn("Hours", typeof(string)) });
dt.Rows.Add("Mudassar", "2018-05-26 21:22:00", "1");
dt.Rows.Add("John", "2018-05-27 21:22:00", "1");
dt.Rows.Add("test");
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
protected void gvCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string date = e.Row.Cells[1].Text;
if (date == " ")
{
TextBox txtHours = e.Row.FindControl("txtHoures") as TextBox;
txtHours.Text = "0";
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Name", GetType(String)), New DataColumn("Date", GetType(String)), New DataColumn("Hours", GetType(String))})
dt.Rows.Add("Mudassar", "2018-05-26 21:22:00", "1")
dt.Rows.Add("John", "2018-05-27 21:22:00", "1")
dt.Rows.Add("test")
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End If
End Sub
Protected Sub gvCustomers_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim date1 As String = e.Row.Cells(1).Text
If date1 = " " Then
Dim txtHours As TextBox = TryCast(e.Row.FindControl("txtHoures"), TextBox)
txtHours.Text = "0"
End If
End If
End Sub
Screenshot