Gridview dynamically add new row

青春壹個敷衍的年華 提交于 2019-12-23 16:22:15

问题


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?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/5511974/gridview-dynamically-add-new-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!