Hi satabeach,
Refer below sample.
For insert refer below links -
HTML
<asp:GridView ID="gvCustomers" runat="server">
</asp:GridView>
Namespaces
C#
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = GetData();
dt.Columns.Add("Sequence", typeof(int));
int value = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i % 3 > 0 || i == 0)
{
dt.Rows[i]["Sequence"] = value;
}
else
{
value++;
dt.Rows[i]["Sequence"] = value;
}
}
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
private DataTable GetData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT TOP 6 CustomerID,ContactName FROM Customers", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
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 = GetData()
dt.Columns.Add("Sequence", GetType(Integer))
Dim value As Integer = 1
For i As Integer = 0 To dt.Rows.Count - 1
If i Mod 3 > 0 OrElse i = 0 Then
dt.Rows(i)("Sequence") = value
Else
value += 1
dt.Rows(i)("Sequence") = value
End If
Next
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End If
End Sub
Private Function GetData() As DataTable
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("SELECT TOP 6 CustomerID,ContactName FROM Customers", con)
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Return dt
End Function
Screenshot