Hi ramco1917,
Please refer below sample.
SQL
CREATE TABLE [StudentsData]
(
[StudentName] VARCHAR (30),
[StudentCode] VARCHAR (30),
[Address] VARCHAR (30)
)
GO
INSERT INTO [StudentsData] VALUES ('ABC','36565','India')
INSERT INTO [StudentsData] VALUES ('ZXA','52121','UK')
INSERT INTO [StudentsData] VALUES ('SXZ','24524','France')
INSERT INTO [StudentsData] VALUES ('EDC','54024','Russia')
GO
CREATE PROCEDURE GetStudentsData
AS
BEGIN
SELECT StudentName, StudentCode, Address
FROM StudentsData
END
GO
EXEC GetStudentsData
HTML
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false"
OnRowDataBound="gvDetails_DataBound">
<Columns>
<asp:BoundField HeaderText="Name" DataField="StudentName" />
<asp:BoundField HeaderText="Code" DataField="StudentCode" />
<asp:BoundField HeaderText="Address" DataField="Address" />
</Columns>
</asp:GridView>
Namesapce
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("GetStudentsData", con))
{
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
gvDetails.DataSource = cmd.ExecuteReader();
gvDetails.DataBind();
con.Close();
}
}
}
}
protected void gvDetails_DataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = "Mark";
e.Row.Cells.Add(headerCell);
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell = new TableCell();
cell.Text = ((e.Row.RowIndex + 1) * 10).ToString();
e.Row.Cells.Add(cell);
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("GetStudentsData", con)
cmd.CommandType = CommandType.StoredProcedure
con.Open()
gvDetails.DataSource = cmd.ExecuteReader()
gvDetails.DataBind()
con.Close()
End Using
End Using
End If
End Sub
Protected Sub gvDetails_DataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Header Then
Dim headerCell As TableHeaderCell = New TableHeaderCell()
headerCell.Text = "Mark"
e.Row.Cells.Add(headerCell)
End If
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = New TableCell()
cell.Text = ((e.Row.RowIndex + 1) * 10).ToString()
e.Row.Cells.Add(cell)
End If
End Sub
Screenshot