Hi Makumbi,
Please refer below sample.
Note: For this sample i have used temporary DataTable. For more details refer How to create Temporary Table in ASP.Net using C# and VB.Net.
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" ShowFooter="true">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="Customer Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" Text='<%# Eval("Country") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txtCountry" />
</FooterTemplate>
</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)
{
this.BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("CustomerId", typeof(int)),
new DataColumn("Name"),
new DataColumn("Country")
});
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
this.gvCustomers.DataSource = dt;
this.gvCustomers.DataBind();
}
protected void Submit(object sender, EventArgs e)
{
string country = (gvCustomers.FooterRow.FindControl("txtCountry") as TextBox).Text;
if (string.IsNullOrEmpty(country))
{
(gvCustomers.FooterRow.FindControl("txtCountry") as TextBox).Focus();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("CustomerId", GetType(Integer)), New DataColumn("Name"), New DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
Me.gvCustomers.DataSource = dt
Me.gvCustomers.DataBind()
End Sub
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
Dim country As String = (TryCast(gvCustomers.FooterRow.FindControl("txtCountry"), TextBox)).Text
If String.IsNullOrEmpty(country) Then
TryCast(gvCustomers.FooterRow.FindControl("txtCountry"), TextBox).Focus()
End If
End Sub
Screenshot