Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 742
pinki Avatar asked Feb 27 '26 00:02

pinki


1 Answers

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;
    }
}
like image 114
Muhammad Akhtar Avatar answered Mar 01 '26 13:03

Muhammad Akhtar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!