sorry this is my code.. when i add new row, the page will reload then the file lik upload is missing
mkpkform.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="mkpkform.aspx.cs" Inherits="moe.mkpkform" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 123%;
height: 25px;
}
.auto-style2 {
width: 30px;
}
.auto-style3 {
width: 81px;
}
.auto-style4 {
width: 208px;
}
.auto-style5 {
width: 86px;
}
.auto-style6 {
height: 205px;
}
.auto-style7 {
width: 518px;
}
.auto-style8 {
height: 205px;
width: 518px;
}
.auto-style9 {
width: 155px;
}
</style>
<script type = "text/javascript">
window.onload = function () {
var scrollY = parseInt('<%=Request.Form["scrollY"] %>');
if (!isNaN(scrollY)) {
window.scrollTo(0, scrollY);
}
};
window.onscroll = function () {
var scrollY = document.body.scrollTop;
if (scrollY == 0) {
if (window.pageYOffset) {
scrollY = window.pageYOffset;
}
else {
scrollY = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
}
if (scrollY > 0) {
var input = document.getElementById("scrollY");
if (input == null) {
input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("id", "scrollY");
input.setAttribute("name", "scrollY");
document.forms[0].appendChild(input);
}
input.value = scrollY;
}
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label15" runat="server" style="text-align: left" Text="PERMOHONAN PENGIKTIRAFAN"></asp:Label>
<br />
<br />
<table class="auto-style1">
<tr>
<td class="auto-style2">1.</td>
<td class="auto-style3">
<asp:Label ID="Label1" runat="server" Text="TITLE: "></asp:Label>
</td>
<td class="auto-style5">
</td>
<td class="auto-style4">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="Awang">AWANG</asp:ListItem>
<asp:ListItem>AWANGKU</asp:ListItem>
<asp:ListItem>DAYANG</asp:ListItem>
<asp:ListItem>DAYANGKU</asp:ListItem>
<asp:ListItem Value="PENGIRAN"></asp:ListItem>
<asp:ListItem>PEHIN</asp:ListItem>
<asp:ListItem>DATO</asp:ListItem>
<asp:ListItem>DATIN</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">2.</td>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server" Text="NAME: "></asp:Label>
</td>
<td class="auto-style5">
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">3.</td>
<td class="auto-style3">
<asp:Label ID="Label3" runat="server" Text="I/C: "></asp:Label>
</td>
<td class="auto-style5">
NUMBER:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox2" runat="server" MaxLength="9"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label4" runat="server" Text="COLOR: "></asp:Label>
</td>
<td class="auto-style4">
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>YELLOW</asp:ListItem>
<asp:ListItem>GREEN</asp:ListItem>
<asp:ListItem>RED</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
<td class="auto-style5">
UPLOAD IC SCAN:</td>
<td class="auto-style4">
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">4.</td>
<td class="auto-style3">
<asp:Label ID="Label14" runat="server" Text="RELIGION: "></asp:Label>
</td>
<td class="auto-style5">
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">5.</td>
<td class="auto-style3">
<asp:Label ID="Label5" runat="server" Text="ADDRESS: "></asp:Label>
</td>
<td class="auto-style5">
NO</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox3" runat="server" Width="25px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
LOT</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox16" runat="server" Width="25px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label7" runat="server" Text="SPG"></asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox12" runat="server" Width="71px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label8" runat="server" Text="JALAN"></asp:Label>
</td>
<td class="auto-style4"><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label9" runat="server" Text="KG"></asp:Label>
</td>
<td class="auto-style4"><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label10" runat="server" Text="DAERAH"></asp:Label>
</td>
<td class="auto-style4"><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
<asp:Label ID="Label11" runat="server" Text="POSTCODE"></asp:Label>
</td>
<td class="auto-style4"><asp:TextBox ID="TextBox8" runat="server" MaxLength="6"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
<td class="auto-style5"> </td>
<td class="auto-style4">BRUNEI DARUSSALAM</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">6.</td>
<td class="auto-style3">
<asp:Label ID="Label12" runat="server" Text="TEL NO."></asp:Label>
</td>
<td class="auto-style5">
MOBILE:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
<td class="auto-style5">
HOME:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
<td class="auto-style5">
OFFICE:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox14" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3"> </td>
<td class="auto-style5">
EMERGENCY:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox15" runat="server"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">7.</td>
<td class="auto-style3">
<asp:Label ID="Label13" runat="server" Text="EMAIL: "></asp:Label>
</td>
<td class="auto-style5">
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox10" runat="server" Width="216px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style3">
</td>
<td class="auto-style5">
</td>
<td class="auto-style4">
</td>
<td> </td>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
</div>
<div>
<asp:Label ID="Label6" runat="server" style="text-align: left" Text="BUTIR MAKLUMAT PENDIDIKAN"></asp:Label>
<br />
<br />
<table>
<tr>
<td>1.</td>
<td class="auto-style7">GCE O LEVEL</td>
</tr>
<tr>
<td class="auto-style6"></td>
<td class="auto-style8">
<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnSelectedIndexChanged="Gridview1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Year">
<ItemTemplate>
<asp:DropDownList ID="TextBox1" runat="server">
<asp:ListItem>May/June 2010</asp:ListItem>
<asp:ListItem>August/September 2010</asp:ListItem>
<asp:ListItem>May/June 2011</asp:ListItem>
<asp:ListItem>August/September 2011</asp:ListItem>
<asp:ListItem>May/June 2012</asp:ListItem>
<asp:ListItem>August/September 2012</asp:ListItem>
<asp:ListItem>May/June 2013</asp:ListItem>
<asp:ListItem>August/September 2013</asp:ListItem>
<asp:ListItem>May/June 2014</asp:ListItem>
<asp:ListItem>August/September 2014</asp:ListItem>
<asp:ListItem>May/June 2015</asp:ListItem>
<asp:ListItem>August/September 2015</asp:ListItem>
<asp:ListItem>May/June 2016</asp:ListItem>
<asp:ListItem>August/September 2016</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grade">
<ItemTemplate>
<asp:DropDownList ID="TextBox3" runat="server">
<asp:ListItem>A1</asp:ListItem>
<asp:ListItem>A2</asp:ListItem>
<asp:ListItem>B3</asp:ListItem>
<asp:ListItem>C5</asp:ListItem>
<asp:ListItem>D7</asp:ListItem>
<asp:ListItem>D8</asp:ListItem>
<asp:ListItem>E9</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="Gridview1_SelectedIndexChanged"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
<tr>
<td>2. </td>
<td class="auto-style7">GCE A LEVEL</td>
</tr>
<tr>
<td></td>
<td class="auto-style7">
<asp:gridview ID="Gridview2" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnSelectedIndexChanged="Gridview1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="RowNumber2" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Year">
<ItemTemplate>
<asp:DropDownList ID="TextBox4" runat="server">
<asp:ListItem>May/June 2010</asp:ListItem>
<asp:ListItem>August/September 2010</asp:ListItem>
<asp:ListItem>May/June 2011</asp:ListItem>
<asp:ListItem>August/September 2011</asp:ListItem>
<asp:ListItem>May/June 2012</asp:ListItem>
<asp:ListItem>August/September 2012</asp:ListItem>
<asp:ListItem>May/June 2013</asp:ListItem>
<asp:ListItem>August/September 2013</asp:ListItem>
<asp:ListItem>May/June 2014</asp:ListItem>
<asp:ListItem>August/September 2014</asp:ListItem>
<asp:ListItem>May/June 2015</asp:ListItem>
<asp:ListItem>August/September 2015</asp:ListItem>
<asp:ListItem>May/June 2016</asp:ListItem>
<asp:ListItem>August/September 2016</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject">
<ItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grade">
<ItemTemplate>
<asp:DropDownList ID="TextBox6" runat="server">
<asp:ListItem>A1</asp:ListItem>
<asp:ListItem>A2</asp:ListItem>
<asp:ListItem>B3</asp:ListItem>
<asp:ListItem>C5</asp:ListItem>
<asp:ListItem>D7</asp:ListItem>
<asp:ListItem>D8</asp:ListItem>
<asp:ListItem>E9</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd2" runat="server" Text="Add New Row" OnClick="ButtonAdd2_Click"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
<tr>
<td>3.</td>
<td class="auto-style7">LAIN - LAIN KELULUSAN</td>
</tr>
<tr>
<td></td>
<td class="auto-style7">
<asp:gridview ID="Gridview3" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnSelectedIndexChanged="Gridview1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="RowNumber3" HeaderText="Row Number" />
<asp:TemplateField HeaderText="KELULUSAN">
<ItemTemplate>
<asp:DropDownList ID="TextBox7" runat="server">
<asp:ListItem>HND</asp:ListItem>
<asp:ListItem>DEGREE</asp:ListItem>
<asp:ListItem>MASTER</asp:ListItem>
<asp:ListItem>PHD</asp:ListItem>
<asp:ListItem>OTHERS</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nama">
<ItemTemplate>
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd3" runat="server" Text="Add New Row" OnClick="ButtonAdd3_Click"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
<br />
<br />
</td>
</tr>
</table>
</div>
<div>
<asp:Label ID="Label16" runat="server" Text="Maklumat Pengiktirafan"></asp:Label>
<table>
<tr>
<td class="auto-style9">Pilih</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem>KURSUS</asp:ListItem>
<asp:ListItem>KELULUSAN</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style9">Nama Kursus / Kelulusan</td>
<td>
<asp:Panel id="loginPanel" DefaultButton="btnone" Runat="Server">
<asp:TextBox ID="TextBox17" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqValFName" runat="server" ControlToValidate="TextBox17"
Display="Dynamic" EnableClientScript="False" ErrorMessage="Masukkan nama mu bh"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="btnone" runat="server" Text="Submit" ValidationGroup="one" Visible="false" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
<tr>
<td>Dari Institusi / Kolej / Universiti</td>
<td>
<asp:Panel id="Panel1" DefaultButton="btnone" Runat="Server">
<asp:TextBox ID="TextBox18" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox18"
Display="Dynamic" EnableClientScript="False" ErrorMessage="nama sekulah mu"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="Button2" runat="server" Text="Submit" ValidationGroup="one" Visible="false" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
<tr>
<td>Negara</td>
<td>
<asp:Panel id="Panel2" DefaultButton="btnone" Runat="Server">
<asp:TextBox ID="TextBox19" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox19"
Display="Dynamic" EnableClientScript="False" ErrorMessage="nama negara mu"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="Button3" runat="server" Text="Submit" ValidationGroup="one" Visible="false" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
<tr>
<td>Pilih Satu sja pls</td>
<td>
<asp:Panel id="Panel3" DefaultButton="btnone" Runat="Server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Full Time</asp:ListItem>
<asp:ListItem>Part Time</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="RadioButtonList1"
Display="Dynamic" EnableClientScript="False" ErrorMessage="Pilih satu pls"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="Button4" runat="server" Text="Submit" ValidationGroup="one" Visible="false" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
<tr>
<td>Duration</td>
<td>
<asp:Panel id="Panel4" DefaultButton="btnone" Runat="Server">
<asp:TextBox ID="TextBox21" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox21"
Display="Dynamic" EnableClientScript="False" ErrorMessage="Brapa lama"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="Button5" runat="server" Text="Submit" ValidationGroup="one" Visible="false" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
<tr>
<td>Tujuan Permohonan</td>
<td>
<asp:Panel id="Panel5" DefaultButton="btnone" Runat="Server">
<asp:RadioButtonList ID="RadioButtonList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged">
<asp:ListItem Value="Dermasiswa" Selected="False">Dermasiswa</asp:ListItem>
<asp:ListItem Value="Pekerjaan" Selected="False">Pekerjaan</asp:ListItem>
<asp:ListItem Value="Melanjutkan pelajaran" Selected="False">Melanjutkan pelajaran</asp:ListItem>
<asp:ListItem Value="Other" Selected="False">Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="TextBox20" runat="server" Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="RadioButtonList2"
Display="Dynamic" EnableClientScript="False" ErrorMessage="Pilih satu jua"
ValidationGroup="one"></asp:RequiredFieldValidator>
<asp:Button ID="Button6" runat="server" Text="Submit" ValidationGroup="one" OnClick="btnone_Click" />
</asp:Panel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
mkpkform.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
//using MySql.Data.MySqlClient;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Data;
namespace moe
{
public partial class mkpkform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetInitialRow();
SetInitialRow2();
SetInitialRow3();
}
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
Gridview1.DataSource = dt;
Gridview1.DataBind();
}
private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
DropDownList box1 = (DropDownList)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
DropDownList box3 = (DropDownList)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtCurrentTable.Rows[i - 1]["Column1"] = box1.Text;
dtCurrentTable.Rows[i - 1]["Column2"] = box2.Text;
dtCurrentTable.Rows[i - 1]["Column3"] = box3.Text;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
Gridview1.DataSource = dtCurrentTable;
Gridview1.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList box1 = (DropDownList)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
DropDownList box3 = (DropDownList)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
box1.Text = dt.Rows[i]["Column1"].ToString();
box2.Text = dt.Rows[i]["Column2"].ToString();
box3.Text = dt.Rows[i]["Column3"].ToString();
rowIndex++;
}
}
}
}
protected void Gridview1_SelectedIndexChanged(object sender, EventArgs e)
{
/* if(btn_ID == ButtonAdd)
{ */
AddNewRowToGrid();
/* }
if(btn_ID == ButtonAdd2)
{
AddNewRowToGrid2();
} */
}
private void SetInitialRow2()
{
DataTable dt2 = new DataTable();
DataRow dr2 = null;
dt2.Columns.Add(new DataColumn("RowNumber2", typeof(string)));
dt2.Columns.Add(new DataColumn("Column4", typeof(string)));
dt2.Columns.Add(new DataColumn("Column5", typeof(string)));
dt2.Columns.Add(new DataColumn("Column6", typeof(string)));
dr2 = dt2.NewRow();
dr2["RowNumber2"] = 1;
dr2["Column4"] = string.Empty;
dr2["Column5"] = string.Empty;
dr2["Column6"] = string.Empty;
dt2.Rows.Add(dr2);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable2"] = dt2;
Gridview2.DataSource = dt2;
Gridview2.DataBind();
}
private void AddNewRowToGrid2()
{
int rowIndex = 0;
if (ViewState["CurrentTable2"] != null)
{
DataTable dtCurrentTable2 = (DataTable)ViewState["CurrentTable2"];
DataRow drCurrentRow2 = null;
if (dtCurrentTable2.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable2.Rows.Count; i++)
{
//extract the TextBox values
DropDownList box4 = (DropDownList)Gridview2.Rows[rowIndex].Cells[1].FindControl("TextBox4");
TextBox box5 = (TextBox)Gridview2.Rows[rowIndex].Cells[2].FindControl("TextBox5");
DropDownList box6 = (DropDownList)Gridview2.Rows[rowIndex].Cells[3].FindControl("TextBox6");
drCurrentRow2 = dtCurrentTable2.NewRow();
drCurrentRow2["RowNumber2"] = i + 1;
dtCurrentTable2.Rows[i - 1]["Column4"] = box4.Text;
dtCurrentTable2.Rows[i - 1]["Column5"] = box5.Text;
dtCurrentTable2.Rows[i - 1]["Column6"] = box6.Text;
rowIndex++;
}
dtCurrentTable2.Rows.Add(drCurrentRow2);
ViewState["CurrentTable2"] = dtCurrentTable2;
Gridview2.DataSource = dtCurrentTable2;
Gridview2.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData2();
}
private void SetPreviousData2()
{
int rowIndex = 0;
if (ViewState["CurrentTable2"] != null)
{
DataTable dt2 = (DataTable)ViewState["CurrentTable2"];
if (dt2.Rows.Count > 0)
{
for (int i = 0; i < dt2.Rows.Count; i++)
{
DropDownList box4 = (DropDownList)Gridview2.Rows[rowIndex].Cells[1].FindControl("TextBox4");
TextBox box5 = (TextBox)Gridview2.Rows[rowIndex].Cells[2].FindControl("TextBox5");
DropDownList box6 = (DropDownList)Gridview2.Rows[rowIndex].Cells[3].FindControl("TextBox6");
box4.Text = dt2.Rows[i]["Column4"].ToString();
box5.Text = dt2.Rows[i]["Column5"].ToString();
box6.Text = dt2.Rows[i]["Column6"].ToString();
rowIndex++;
}
}
}
}
protected void ButtonAdd2_Click(object sender, EventArgs e)
{
AddNewRowToGrid2();
}
private void SetInitialRow3()
{
DataTable dt3 = new DataTable();
DataRow dr3 = null;
dt3.Columns.Add(new DataColumn("RowNumber3", typeof(string)));
dt3.Columns.Add(new DataColumn("Column7", typeof(string)));
dt3.Columns.Add(new DataColumn("Column8", typeof(string)));
dr3 = dt3.NewRow();
dr3["RowNumber3"] = 1;
dr3["Column7"] = string.Empty;
dr3["Column8"] = string.Empty;
dt3.Rows.Add(dr3);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable3"] = dt3;
Gridview3.DataSource = dt3;
Gridview3.DataBind();
}
private void AddNewRowToGrid3()
{
int rowIndex = 0;
if (ViewState["CurrentTable3"] != null)
{
DataTable dtCurrentTable3 = (DataTable)ViewState["CurrentTable3"];
DataRow drCurrentRow3 = null;
if (dtCurrentTable3.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable3.Rows.Count; i++)
{
//extract the TextBox values
DropDownList box7 = (DropDownList)Gridview3.Rows[rowIndex].Cells[1].FindControl("TextBox7");
TextBox box8 = (TextBox)Gridview3.Rows[rowIndex].Cells[2].FindControl("TextBox8");
drCurrentRow3 = dtCurrentTable3.NewRow();
drCurrentRow3["RowNumber3"] = i + 1;
dtCurrentTable3.Rows[i - 1]["Column7"] = box7.Text;
dtCurrentTable3.Rows[i - 1]["Column8"] = box8.Text;
rowIndex++;
}
dtCurrentTable3.Rows.Add(drCurrentRow3);
ViewState["CurrentTable3"] = dtCurrentTable3;
Gridview3.DataSource = dtCurrentTable3;
Gridview3.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData3();
}
private void SetPreviousData3()
{
int rowIndex = 0;
if (ViewState["CurrentTable3"] != null)
{
DataTable dt3 = (DataTable)ViewState["CurrentTable3"];
if (dt3.Rows.Count > 0)
{
for (int i = 0; i < dt3.Rows.Count; i++)
{
DropDownList box7 = (DropDownList)Gridview3.Rows[rowIndex].Cells[1].FindControl("TextBox7");
TextBox box8 = (TextBox)Gridview3.Rows[rowIndex].Cells[2].FindControl("TextBox8");
box7.Text = dt3.Rows[i]["Column7"].ToString();
box8.Text = dt3.Rows[i]["Column8"].ToString();
rowIndex++;
}
}
}
}
protected void ButtonAdd3_Click(object sender, EventArgs e)
{
AddNewRowToGrid3();
}
protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (string.Equals(RadioButtonList2.SelectedValue, "Other"))
{
TextBox20.Visible = true;
}
else
{
TextBox20.Visible = false;
}
}
protected void btnone_Click(object sender, EventArgs e)
{
Page.Validate("one");
}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add(TextBox10.Text);
mail.From = new MailAddress("wadtassignment@gmail.com");
mail.Subject = "Pemohonan Pengiktirafan";
mail.IsBodyHtml = true;
mail.Body = DropDownList1.Text + " " + TextBox1.Text + ","
;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential
("wadtassignment@gmail.com", "wadt1234");
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
}