Gridview dynamically add new row
I have a file Upload control and I have a button Upload ., so when the click vent fires., I want a new row to be created in开发者_开发问答 the gridview and get the fileName and bind to a column And show it on the page.
Any ideas how to do please?
here is code...
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
if (Session["dtbl"] == null)
{
DataTable dtbl = new DataTable();
DataColumn FileName = new DataColumn("FileName", System.Type.GetType("System.String"));
dtbl.Columns.Add(FileName);
Session["dtbl"] = dtbl;
}
DataTable dtbl = (DataTable)Session["dtbl"];
DataRow myRow;
myRow = dt.NewRow();
myRow["FileName"] = FileUpload1.FileName;
dtbl.Rows.Add(myRow);
gridView1.DataSource = dtbl.DefaultView;
gridView1.DataBind();
Session["dtbl"] = dtbl;
}
}
精彩评论