我在row_created事件中动态创建了页脚行,并在按钮点击上添加动态创建的控件,这也是在页脚中动态创建的我想在linq表中保存数据但是dosen&t; t 这是我的代码,我真的需要帮助
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
GridViewRow foter = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
GridViewRow foter1 = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
GridViewRow foter2 = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
GridViewRow foter3 = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
TableCell span = new TableCell();
span.Attributes.Add("rowspan", "3");
span.Attributes.Add("width", "180px");
FileUpload f = new FileUpload();
f.ID = "flupImage";
f.Attributes.Add("onchange", "ShowpImagePreview(this);");
Image img = new Image();
img.ID = "ImgPrv";
img.ClientIDMode = System.Web.UI.ClientIDMode.Static;
img.Attributes.Add("Height", "60px");
img.Attributes.Add("Width", "60px");
span.Controls.Add(img);
span.Controls.Add(new LiteralControl("<br />"));
span.Controls.Add(f);
span.HorizontalAlign = HorizontalAlign.Left;
TableCell celf = new TableCell();
Label l1 = new Label();
l1.Text = "ID ";
TextBox t1 = new TextBox();
t1.ID = "id";
celf.Controls.Add(l1);
celf.Controls.Add(t1);
celf.ColumnSpan = 4;
celf.HorizontalAlign = HorizontalAlign.Right;
TableCell celf2 = new TableCell();
Label l2 = new Label();
l2.Text = "naziv";
TextBox t2 = new TextBox();
t2.ID = "naziv";
celf2.Controls.Add(l2);
celf2.Controls.Add(t2);
celf2.ColumnSpan = 3;
celf2.HorizontalAlign = HorizontalAlign.Right;
TableCell celf3 = new TableCell();
Label l3 = new Label();
l3.Text = "opis";
TextBox t3 = new TextBox();
t3.ID = "opis";
celf3.Controls.Add(l3);
celf3.Controls.Add(t3);
celf3.ColumnSpan = 4;
celf3.HorizontalAlign = HorizontalAlign.Right;
TableCell celf4 = new TableCell();
Label l4 = new Label();
l4.Text = "cena";
TextBox t4 = new TextBox();
t4.ID = "cena";
celf4.Controls.Add(l4);
celf4.Controls.Add(t4);
celf4.ColumnSpan = 3;
celf4.HorizontalAlign = HorizontalAlign.Right;
TableCell celf5 = new TableCell();
Label l6 = new Label();
l6.Text = "kategorija";
TextBox t6 = new TextBox();
t6.ID = "kategorija";
celf5.Controls.Add(l6);
celf5.Controls.Add(t6);
celf5.ColumnSpan = 7;
celf5.HorizontalAlign = HorizontalAlign.Right;
TableCell celf6 = new TableCell();
Button Button1 = new Button();
Button1.Text = "ubaci nov";
celf6.Controls.Add(Button1);
Button1.Click += new System.EventHandler(Button1_Click);
celf6.ColumnSpan = 7;
celf6.HorizontalAlign = HorizontalAlign.Center;
foter.Cells.Add(span);
foter.Cells.Add(celf);
foter.Cells.Add(celf2);
foter1.Cells.Add(celf3);
foter1.Cells.Add(celf4);
foter2.Cells.Add(celf5);
foter3.Cells.Add(celf6);
GridView1.Controls[0].Controls.Add(foter);
GridView1.Controls[0].Controls.Add(foter1);
GridView1.Controls[0].Controls.Add(foter2);
GridView1.Controls[0].Controls.Add(foter3);
}
}
&#13;
protected void Button1_Click(object sender, EventArgs e)
{
DataClasses1DataContext data = new DataClasses1DataContext();
Proizvodi video = new Proizvodi();
FileUpload file = (GridView1.FooterRow.FindControl("flupImage") as FileUpload);
byte[] fileByte = file.FileBytes;
Binary bin = new Binary(fileByte);
video.slika = bin;
string prID = (GridView1.FooterRow.FindControl("id") as TextBox).Text;
int proID = Convert.ToInt32(prID);
video.proizvodID = proID;
string naziv = (GridView1.FooterRow.FindControl("naziv") as TextBox).Text;
video.naziv = naziv;
string opis = (GridView1.FooterRow.FindControl("opis") as TextBox).Text;
video.opis = opis;
decimal cena=Convert.ToDecimal( (GridView1.FooterRow.FindControl("cena") as TextBox).Text);
video.cena = cena;
string katId = (GridView1.FooterRow.FindControl("kategorija") as TextBox).Text;
video.kategorijaID = Convert.ToInt32(katId);
data.Proizvodis.InsertOnSubmit(video);
data.SubmitChanges();
GridView1.DataBind();
}
&#13;
我从网上尝试了一些解决方案但是没有工作。 请帮忙