Dataset, databinding, and other fun ways to demonstrate my ignorance.

M

Merennulli

Ok, the project is this - I've got an upload directory on an internal
server that is filled by an upload webform. This webform is working
fine. So is reading in the list of files and displaying it. Now I want
to add the ability to delete files from there. In old ASP or any other
language I've worked with, I'd just make that listing spit out links
with ?delete=id and tie the ID to the filename using server variables
or ?delete=encryptedfilename.

With ASP.NET, the querystring keeps getting passed, so after that click
to delete, each subsequent click also pulls in that querystring unless
it's another delete that overwrites it. I could put a "Not
Page.IsPostBack" around the delete, but I can't help but believe
there's a better way in .NET.

My thought was to use a checklistbox and databind it to a dataset that
I populate with the filenames. I'm quickly discovering my knowlege of
datasets is limited to filling and using them, not populating them
manually, and this is my first time using databinding.

Dim filesLength = 0
Dim filesMax = dirinfo.GetFiles.Length
Dim myRow As DataRow = tbl1.NewRow
Dim filestring As String
dsFiles.BeginInit()
While filesLength < filesMax

filestring =
dirinfo.GetFiles.GetValue(filesLength).ToString()
myRow("filename") = filestring
tbl1.Rows.Add(myRow)
filesLength = filesLength + 1
End While

As you can probably tell, this errors on the second time through,
saying myRow already belongs to the table. If I take that out, it just
keeps overwriting myRow rather than adding a new row.

I can databind, though, and it does catch that last value. I tried
forming a simple list and that caught all the information, but then
wouldn't databind.

Is there a better solution?
Even if there is, what should I be doing to add a new row to the
dataset? My books and google results wouldn't answer that for me.
 
G

Guest

You need to do something like this:

Dim myRow As DataRow
While filesLength < filesMax

filestring =
dirinfo.GetFiles.GetValue(filesLength).ToString()
myRow=tbl1.NewRow
myRow("filename") = filestring
tbl1.Rows.Add(myRow)
filesLength = filesLength + 1
End While


Do you see the difference?

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top