By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Mar 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Merennulli" wrote:
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.

Mar 13 '06 #2

P: n/a
Ah, I forgot to use NewRow in the loop. That makes a bit more sense.
Thank you.

Mar 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.