Hi lingers,
It can be done in two ways.
1. Using ASPX page
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Candara" Width="100%">
<Columns>
<asp:BoundField DataField="orderid" HeaderText="id" ItemStyle-Width="30" />
<asp:BoundField DataField="purchaseorderno" HeaderText="PO NO" ItemStyle-Width="100" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" />
<asp:TemplateField HeaderText="Date" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox ID="txtdate" runat="server" Width="200"
Text='<%#DateTime.Today.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) %>'></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Waybill">
<ItemTemplate>
<asp:TextBox ID="txtwaybill" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtcomment" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Baseno" ItemStyle-Width="200">
<ItemTemplate>
<ul id="myTags" class="myTags">
</ul>
<asp:HiddenField ID="hfIds" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[3] {
new System.Data.DataColumn("orderid"),
new System.Data.DataColumn("purchaseorderno"),
new System.Data.DataColumn("quantity") });
dt.Rows.Add(1, 11, 10);
dt.Rows.Add(2, 12, 5);
dt.Rows.Add(3, 13, 17);
dt.Rows.Add(4, 14, 8);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
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 Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn(2) {
New Data.DataColumn("orderid"),
New Data.DataColumn("purchaseorderno"),
New Data.DataColumn("quantity")})
dt.Rows.Add(1, 11, 10)
dt.Rows.Add(2, 12, 5)
dt.Rows.Add(3, 13, 17)
dt.Rows.Add(4, 14, 8)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
2. Using OnRowDataBound event
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Candara" Width="100%"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="orderid" HeaderText="id" ItemStyle-Width="30" />
<asp:BoundField DataField="purchaseorderno" HeaderText="PO NO" ItemStyle-Width="100" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" />
<asp:TemplateField HeaderText="Date" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox ID="txtdate" runat="server" Width="200"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Waybill">
<ItemTemplate>
<asp:TextBox ID="txtwaybill" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtcomment" runat="server" Width="100"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Baseno" ItemStyle-Width="200">
<ItemTemplate>
<ul id="myTags" class="myTags">
</ul>
<asp:HiddenField ID="hfIds" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[3] {
new System.Data.DataColumn("orderid"),
new System.Data.DataColumn("purchaseorderno"),
new System.Data.DataColumn("quantity") });
dt.Rows.Add(1, 11, 10);
dt.Rows.Add(2, 12, 5);
dt.Rows.Add(3, 13, 17);
dt.Rows.Add(4, 14, 8);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("txtdate") as TextBox).Text =
DateTime.Today.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
}
}
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 Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn(2) {
New Data.DataColumn("orderid"),
New Data.DataColumn("purchaseorderno"),
New Data.DataColumn("quantity")})
dt.Rows.Add(1, 11, 10)
dt.Rows.Add(2, 12, 5)
dt.Rows.Add(3, 13, 17)
dt.Rows.Add(4, 14, 8)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
TryCast(e.Row.FindControl("txtdate"), TextBox).Text =
DateTime.Today.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
End If
End Sub
Screenshot