前台用的是一个dataGrid里面全是模板列,但是为了要让他能出现你要的行数哪么在后台就要为它设置一个
if
(
!
Page.IsPostBack)
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "id";
dc.ReadOnly = true;
dc.Unique = true;
dt.Columns.Add(dc);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
for(int i=0;i<=2;i++)
{
DataRow dr = dt.NewRow();
dr["id"] = i;
dt.Rows.Add(dr);
}
this.DataGrid1.DataSource = ds.Tables[0];
this.DataGrid1.DataBind();
}
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.DataType = System.Type.GetType("System.Int32");
dc.ColumnName = "id";
dc.ReadOnly = true;
dc.Unique = true;
dt.Columns.Add(dc);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
for(int i=0;i<=2;i++)
{
DataRow dr = dt.NewRow();
dr["id"] = i;
dt.Rows.Add(dr);
}
this.DataGrid1.DataSource = ds.Tables[0];
this.DataGrid1.DataBind();
}
你想要几行,在for循环中就几减1,因为是从0开始的。
下面是点提交按钮后的代码。这个提交按钮是在这个datagrid外面的哦
foreach
(DataGridItem dg
in
this
.DataGrid1.Items)
{
HtmlInputFile hif = (HtmlInputFile)dg.FindControl("uploadfile");
DropDownList ddl = (DropDownList)dg.FindControl("FileFormat");
CheckBox cb = (CheckBox)dg.FindControl("C");
TextBox tb = (TextBox)dg.FindControl("Colors");
if(hif.PostedFile.FileName!=null)
{
int C = 0;
string filename = hif.PostedFile.FileName;
string filetype = hif.PostedFile.ContentType;
string lastfilename = filename.Substring(filename.LastIndexOf(".")+1);
if(filetype=="image/gif" || filetype=="image/jpg" || filetype == "image/pjpeg" || filetype =="image/bmp")
{
DateTime dt = DateTime.Now;
string Fname = dt.ToString("yyyyMMddhhmmss") + "." + lastfilename;
string filepath = Server.MapPath("../uploadimage") + """ + Fname;
//this.File1.PostedFile.SaveAs(filepath);
if(cb.Checked==true)
{
C=1;
}
else
{
C=0;
}
Response.Write(Fname+"++"+ddl.SelectedItem.Text+"++"+C+"++"+tb.Text+this.TextBox1.Text+"<br>");
}
else
{
Response.Write("<script>alert('aaaaa');</script>");
}
}
}
}
catch
{
}
{
HtmlInputFile hif = (HtmlInputFile)dg.FindControl("uploadfile");
DropDownList ddl = (DropDownList)dg.FindControl("FileFormat");
CheckBox cb = (CheckBox)dg.FindControl("C");
TextBox tb = (TextBox)dg.FindControl("Colors");
if(hif.PostedFile.FileName!=null)
{
int C = 0;
string filename = hif.PostedFile.FileName;
string filetype = hif.PostedFile.ContentType;
string lastfilename = filename.Substring(filename.LastIndexOf(".")+1);
if(filetype=="image/gif" || filetype=="image/jpg" || filetype == "image/pjpeg" || filetype =="image/bmp")
{
DateTime dt = DateTime.Now;
string Fname = dt.ToString("yyyyMMddhhmmss") + "." + lastfilename;
string filepath = Server.MapPath("../uploadimage") + """ + Fname;
//this.File1.PostedFile.SaveAs(filepath);
if(cb.Checked==true)
{
C=1;
}
else
{
C=0;
}
Response.Write(Fname+"++"+ddl.SelectedItem.Text+"++"+C+"++"+tb.Text+this.TextBox1.Text+"<br>");
}
else
{
Response.Write("<script>alert('aaaaa');</script>");
}
}
}
}
catch
{
}