Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to add Fileupload to my Listview?

$
0
0

Hi,

I created listview with image saved in Database,

Now I want to edit it,

I added File Upload to my listView in Edit Part

Now I want to save new image in Database (Update)

I Added this code to update Button

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            try
            {
                FileUpload fUpload = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
                TextBox txtName = (TextBox)ListView1.InsertItem.FindControl("TextBox3");
                TextBox txtPrice = (TextBox)ListView1.InsertItem.FindControl("TextBox2");

                if (fUpload.HasFile && fUpload.PostedFile.ContentLength > 0)
                {

                    string fileName = fUpload.FileName;
                    byte[] fileByte = fUpload.FileBytes;
                    Binary imgBinary = new Binary(fileByte);

                    TestDataContext db = new TestDataContext();
                    Table1 t = new Table1()
                    {
                        Name = txtName.Text,
                        Price = int.Parse(txtPrice.Text),
                        image = imgBinary,
                    };
                    db.Table1.InsertOnSubmit(t);
                    db.SubmitChanges();

                    ListView1.DataBind();
                }
            }
            catch (Exception ex) { }
        }

What is problem here

Plz Help me THANKS


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>