using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(
object sender, EventArgs e)
{
if (Page.IsPostBack ==
true)
{
AddRows();
}
}
private void AddRows()
{
try
{
if (hidCurRow.Value !=
"" && hidCurRow.Value !=
"0")
{
DecreaseCount();
}
else if(hidCurRow.Value ==
"")
{
IncreaseCount();
}
for (
int count = 1; count < tblMin.Rows.Count; count++)
{
tblMin.Rows.RemoveAt(1);
}
int maxRows = Convert.ToInt32(hidMax.Value);
string[] arrRows = hidRow.Value.Split(
",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (
int count = 1; count <= maxRows; count++)
{
Boolean
isAdd =
false;
for (
int incount = 0; incount < arrRows.Length; incount++)
{
if (arrRows[incount] == count.ToString())
{
isAdd
=
true;
break;
}
}
if (isAdd ==
true)
{
TableRow
tr =
new TableRow();
TableCell
tcfu =
new TableCell();
FileUpload
fup =
new FileUpload();
fup.ID
=
"fu" + count.ToString();
tcfu.Controls.Add(fup);
TableCell
tcbtn =
new TableCell();
Button
bt =
new Button();
bt.ID
=
"btn" + count.ToString();
bt.Text
=
"Remove";
bt.Attributes.Add(
"onclick",
"DecreaseRow('" + count.ToString() +
"');");
tcbtn.Controls.Add(bt);
tr.Cells.Add(tcfu);
tr.Cells.Add(tcbtn);
tblMin.Rows.Add(tr);
}
}
}
catch
{
}
}
private void IncreaseCount()
{
string strVal = hidMax.Value;
if (strVal !=
"")
{
int iMax = Convert.ToInt32(strVal);
iMax
= iMax + 1;
hidMax.Value
= iMax.ToString();
if (hidRow.Value !=
"")
{
hidRow.Value
= hidRow.Value +
"," + iMax.ToString();
}
else
{
hidRow.Value
= iMax.ToString();
}
}
}
private void DecreaseCount()
{
string strCurRow = hidCurRow.Value;
string[] arrRows = hidRow.Value.Split(
",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
hidRow.Value
=
"";
for (
int count = 0; count < arrRows.Length; count++)
{
if (arrRows[count] != strCurRow)
{
if (hidRow.Value ==
"")
{
hidRow.Value
= arrRows[count];
}
else
{
hidRow.Value
= hidRow.Value +
"," + arrRows[count];
}
}
}
}
protected void btnAdd_Click(
object sender, EventArgs e)
{
}
protected void btnSubmit_Click(
object sender, EventArgs e)
{
if (hidRow.Value !=
"")
{
string[] strVal = hidRow.Value.Split(
",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (
int count = 0; count < strVal.Length; count++)
{
FileUpload
fup =
new FileUpload();
fup
= (FileUpload)tblMin.FindControl(
"fu" + strVal[count]);
if (fup !=
null)
{
if (fup.PostedFile !=
null && fup.FileName !=
"")
{
//your code here
}
}
}
}
}
}
ASPX