<%@ Page Language=”C#” %>
<%@ Import Namespace=”System.Data” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
void Page_Load()
{
// Create the DataTable columns
DataTable newDataTable = new DataTable();
newDataTable.Columns.Add(“Id”, typeof(int));
newDataTable.Columns.Add(“StudentName”, typeof(string));
newDataTable.Columns.Add(“StudentFee”, typeof(decimal));
// Mark the Id column as an autoincrement column
newDataTable.Columns[“Id”].AutoIncrement = true;
// Add some data rows
for (int i = 1; i < 11; i++)
{
DataRow newRow = newDataTable.NewRow();
newRow[“StudentName”] = “StudentName “ + i.ToString();
newRow[“StudentFee”] = 1200.34;
newDataTable.Rows.Add(newRow);
}
// Bind DataTable to GridView
GridShowData.DataSource = newDataTable;
GridShowData.DataBind();
}
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head id=”Head1” runat=”server”>
<title>Show DataTable </title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<h1>Students</h1>
<asp:GridView id=”GridShowData” Runat=”server” />
</div>
</form>
</body>
</html>
DataRow States and DataRow Versions When you modify the rows in a DataTable, the DataTable keeps track of the changes that you make. A DataTable maintains both the original and modified version of each row.
Each row in a DataTable has a particular RowState that has one of the following values:
- Unchanged : The row has not been changed.
- Added : The row has been added.
- Modified : The row has been modified.
- Deleted : The row has been deleted.
- Detached : The row has been created but not added to the DataTable.
- Current : The current version of the row.
- Default : The default version of the row.
- Original : The original version of the row.
- Proposed : The version of a row that exists during editing.