473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
2 1084
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
Ah, I forgot to use NewRow in the loop. That makes a bit more sense.
Thank you.

Mar 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PCC | last post by:
I am writing a data access layer for a web service. Data from the web service is to be returned as XML. My design dilemma is this... Should I be returning XML from my stored procedures using...
1
by: Patrick.O.Ige | last post by:
I have been paging with DataSet using "DataGridPageChangedEventArgs" and i guess it works with only Dataset because default paging requires that the DataGrid be able to determine the number of...
2
by: louise raisbeck | last post by:
Hi, There seem to be several ways to update rows in sql. What is the best practice? I have written a medium sized update statement into a stored procedure, taking values from the web text...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
3
by: Steve Teeples | last post by:
I am new to database work. I have a very simple database with only two tables linked by a 1:1 relationship. I've read the tables contents into a dataset and bound the two tables to textbox...
2
by: John Rusk | last post by:
Hi, Does the databinding support in ASP.NET 2.0 support two way databinding to datasets? I have a dataset, which is populated with data. I just want to bind the UI to it. I'm struggling to...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
by: AC [MVP MCMS] | last post by:
Implementing databinding from the ASPX/ASCX file is very straightforward: <asp:XmlDataSource id="XmlDs1" DataFile="">...</> <asp:Repeater> <HeaderTemplate><%#XPath("title")%></> </> However,...
0
by: Chris | last post by:
Hello, I have a problem with re-loading datasets. As a simple example, if I have an SQL table of addresses comprising active and inactive addresss, I wish to load either sub-set by clicking on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.