This is topic Deleting rows from a gridview/datatable? in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=050833

Posted by Blayne Bradley (Member # 8565) on :
 
code:
        Dim CheckBox As CheckBox
Dim KeyId As Int32

For Each GridViewRow As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox = CType(GridViewRow.FindControl("chkSelector"), CheckBox)

If CheckBox.Checked Then
'---Get the database id
KeyId = CType(GridView1.DataKeys.Item(GridViewRow.RowIndex).Value, Int32)

'---Use the KeytId to delete from the database.

End If
Next
GridView1.DataBind()

at CType(GridView1.DataKeys.Item(GridViewRow.RowIndex).Value, Int32)

When i run it to that point it crashes out saying:

quote:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

I am not entirely sure what the issue is, I have my gridview being populated from a datatable. the code for which I made using the session variable like so:

code:
        myDataColumn = New Data.DataColumn
myDataColumn.DataType = GetType(String)
myDataColumn.ColumnName = "Product ID"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Product ID"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
myDataTable.Columns.Add(myDataColumn)

And repeated this several times for each column and then doing this:

code:
            gt = Session("sessionvar")

myrow = gt.NewRow()
myrow(0) = ddlPr_Code.SelectedValue
myrow(1) = ddlPr_Name.SelectedValue
myrow(2) = txtPrice.Text
myrow(3) = txtQuantity.Text
myrow(4) = txtShipping.Text
myrow(5) = (txtQuantity.Text * txtPrice.Text)

gt.Rows.Add(myrow)
GridView1.DataSource = gt
GridView1.DataBind()

voila I have ym gridview populated by what the client wants to "order".

And then i added text boxes and am now trying to figure out how to delete from this gridview but I am not sure how and am currently stumped by the index error.
 
Posted by Mucus (Member # 9735) on :
 
What, is your debugger broken?
 
Posted by Blayne Bradley (Member # 8565) on :
 
I used my debugger and I have no idea what to do about "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index" error.
 
Posted by MrSquicky (Member # 1802) on :
 
I think you may want to see why the index is either negative or not less than the size of the collection.

This is a very basic and common error. edit: and extremely easy to find where it occurs using a debugger.
 
Posted by MattP (Member # 10495) on :
 
It just means that you're asking for a row that doesn't exist - either you're providing a negative row number or a row number greater than the number of rows available. It should be easy to see where that's happening in the debugger.
 
Posted by Blayne Bradley (Member # 8565) on :
 
According to the debugger it is the proper row index.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Also according to the debugger RowIndex=0 (for when there's only 1 row for example) and a ? Gridview1.rows shows a count a 1 row.

0 last I checked was less then 1.
 
Posted by MrSquicky (Member # 1802) on :
 
Well, it's great to get that fixed then.

Blayne, I know exactly what your problem is. It is very easy to find and fix. Look at the error message and check the conditions it is telling you would cause this error.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Easy for you but I don't understand why its not working, the count on number of rows is indeed greater then the current rowindex, I do not understand.

? GridView1.Rows
count 3

? GridView1.Index
2

say i have 3 rows in the GV, and I have checked the chkbox on the third one.

The above is correct but the line of code:

? KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Integer) (interger or int32 i tried both)

gives me the error, I don't understand why the data supplied is correct but its not working.
 
Posted by MattP (Member # 10495) on :
 
Do you have any code following the "'---Use the KeytId to delete from the database." that actually deletes rows?
 
Posted by MrSquicky (Member # 1802) on :
 
Blayne,
In your debug, look at the specific collection you are trying to hit. If there are supposed to be 3 entries, you can try dropping watches onto each of those entries to see if they exist and if they have the values you expect. Do that.
 
Posted by Blayne Bradley (Member # 8565) on :
 
no i dont have a delete thing yet. ill try what squickies says in a minute.
 
Posted by Blayne Bradley (Member # 8565) on :
 
hmm im at a different computer now (different lecture) and I cant seem to find the intermediate window in vs2005
 
Posted by Blayne Bradley (Member # 8565) on :
 
k found the immediate window but i cant drop watches and seems to not debug properly on this computer, says its in design mode when it is not.
 
Posted by MrSquicky (Member # 1802) on :
 
Watches in the immediate window? You should use the watch window for that.
 
Posted by Blayne Bradley (Member # 8565) on :
 
thats the problem i cant find the watch window, this machine Im on now is really weird. (alot of the stuff turns white when i run it until i click on it)
 
Posted by MrSquicky (Member # 1802) on :
 
type ctrl+alt+w 1 when you've hit a breakpoint
 
Posted by Blayne Bradley (Member # 8565) on :
 
says watch is not currently availiable.
 
Posted by MrSquicky (Member # 1802) on :
 
quote:
type ctrl+alt+w 1 when you've hit a breakpoint

 
Posted by Blayne Bradley (Member # 8565) on :
 
I did, thats the error I got.
 
Posted by MrSquicky (Member # 1802) on :
 
I don't know what to tell you then. With standard settings, that should always bring up the watch window in that case.

What do you understand hitting a breakpoint to mean?
 
Posted by Blayne Bradley (Member # 8565) on :
 
liie for example the green arrow debug button i can press multiple times and startup multiple isntances of my asp website, the pause and stop buttons dont appear.
 
Posted by Blayne Bradley (Member # 8565) on :
 
k on a proper debuger machine. what am I watching for again?
 
Posted by MrSquicky (Member # 1802) on :
 
Blayne,
This is not where I lead you by the hand or give you the answer. I've given you enough to figure this out. You're better off on your own from here.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I cant figure it out, it is not figurable out, I do not know anything about how these asp/vb classes/methods work so I do not know where to begin looking or what to look for. How am I supposed to know which .etc does what I want it to do?
 
Posted by Nighthawk (Member # 4176) on :
 
quote:
gt = Session("sessionvar")
Wha-huh? Am I reading this correctly: you're using a data table stored in the Session object?!? This is probably beyond the scope of what you're learning now, but are you aware that IIS serializes access to the Session object? Not to mention the amount of chaos that will ensue if you do things like double-post the page (hit "F5" repeatedly) by accident. This method sounds... well... painful and risky.

Secondly, when I do something related (I don't do it the way you suggest; I do it the "old fashioned" way), I add a unique identifier in to the data set that's a HIDDEN column in the grid. Therefore, when I'm doing things like this, I don't have to worry about the "DataKeys" collection, but I simply access "GridViewRow[UniqueKey]".

I don't even know that the "DataKeys" collection is, but I don't know why you're checking the size of the "Rows" collection. You should be comparing "GridView1.DataKeys.Count" (not "GridView1.Rows.Count") to "GridViewRow.RowIndex".

I'm not a fan of Microsoft's way of doing this; I usually don't even use the ViewState (which I've seen be monumental in size when I do something similar) in cases like this and just create non-ASP controls with the unique identifier as the value.
 
Posted by Blayne Bradley (Member # 8565) on :
 
how do I compare "GridView1.DataKeys.Count" to "GridViewRow.RowIndex"?
 
Posted by MrSquicky (Member # 1802) on :
 
If you weren't you, I wouldn't believe that that was a serious question. For pete's sake, think for yourself.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I don't know what I am doing, how the heck would I know what to do? Thinking accomplishes nothing if no amount of thinking determins what the frak am I supposed to do and google fails on me.
 
Posted by MrSquicky (Member # 1802) on :
 
I'm going to give you the benefit of the doubt and figure you're just really stressed out.

Answer this question. Why would you want to compare GridView1.DataKeys.Count to GridViewRow.RowIndex?
 
Posted by Morbo (Member # 5309) on :
 
People got stuff done before google, Blayne. Debugging sucks but keep plugging.
Good luck. [Smile]
 
Posted by King of Men (Member # 6684) on :
 
Um. You know, Blayne, if you wanted to inspire my confidence that I want to work with you on the converter project, this was kind of not the way to do it. But let me give you a hint anyway. When people say 'think', they don't mean that you should try figuring out the Grand Unified Theory from first principles, they mean that you should step through the code by hand. You do understant what I mean by that, yes?

*Walks off muttering about schools these days*
 
Posted by El JT de Spang (Member # 7742) on :
 
quote:
Originally posted by Blayne Bradley:
Thinking accomplishes nothing if no amount of thinking determins what the frak am I supposed to do and google fails on me.

Thinking also accomplishes nothing if you've no practice at it. I can't imagine how you expect to be a competent coder if you're not willing to spend a few hours debugging your own faulty code.
 
Posted by Mucus (Member # 9735) on :
 
Indeed. It will even be more amazing when Blayne has to debug other people's faulty code.
 
Posted by Blayne Bradley (Member # 8565) on :
 
In the end I think ill just use KeyId = GridViewRow1.RowIndex tha gives what row we want to delete.

however my deletion commands dont wanna work.

The GridView 'GridView1' fired event RowDeleting which wasn't handled.

What does wasn't handled mean?
 
Posted by King of Men (Member # 6684) on :
 
quote:
Originally posted by Blayne Bradley:
I cant figure it out, it is not figurable out, I do not know anything about how these asp/vb classes/methods work so I do not know where to begin looking or what to look for. How am I supposed to know which .etc does what I want it to do?

Ah. That is why there is this nifty thing called documentation. The only way to learn an API is to

a) Use it (you got that part) and
b) Look up what the devil it is actually doing.

I might add that you appear to be learning at the wrong level. You are figuring out - slowly, with many 'Hatrack lookups' and probably much pestering of TAs, how to solve specific problems using buggy, fragile, impossible-to-maintain code. What you ought to be learning is how to think about solving problems using an unfamiliar API/language/toolset. You ought to have a general process for becoming familiar with an API at least at the overview level (not too easy with the vast libraries Microsoft puts out, I admit). You should know roughly the methods that each class you use often offers, and preferably have a rough idea of what they do. The only way to get this is to look at the documentation, not just in a frantic search for what you need right now, but also as the literature of your field, to get some idea of what's there.

A further point is that you appear to be suffering from the ill effects of this problem at the more basic level as well. You don't just have a problem with APIs, you have a similar problem in that you didn't learn to think about algorithms for problem-solving in a general way, you only learned to solve specific problems - using bad, buggy code and many Hatrack lookups. (I recall spending three hours in chat trying to make you understand pointers. Can I have them back, please?) To make an analogy with math, you never learned to do addition, you just learned that '10' was the correct answer if the question was '5+5'.

You have got to go back to basics, learn how to write pseudo-code that expresses what the problem is and how you intend to solve it, and learn to program, not to hack together specific solutions.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Exams coming up no time to "go back to basics" and the exams require the work having actually being done since they open book open notes.

As for those hours we were playing CK at the same time, so no soup for you!
 
Posted by Blayne Bradley (Member # 8565) on :
 
here's my current code:

code:
        For Each GridViewRow1 As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)
Dim instance As New GridViewRowEventHandler

If CheckBox1.Checked Then
chkBox = True

'Dim ProductID As String = GridView1.DataKeys(GridViewRow1.RowIndex)("pr_code").ToString
'---Get the database id
KeyId = GridViewRow1.RowIndex
'KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Int32)
'---Use the KeytId to delete from the database.
'GridView1.DeleteRow(KeyId)

gt.Rows(KeyId).Delete()
GridView1.DeleteRow(KeyId)



End If
Next
GridView1.DataSource = gt
GridView1.DataBind()

gt.Rows(KeyId).Delete()
GridView1.DeleteRow(KeyId)

there lines aren't working right. Is the second line the correct way to delete a gridview row, or am i doing ti wrong.
 
Posted by Blayne Bradley (Member # 8565) on :
 
The ASP course doesn't teach us anything bout methods, how to use them or what they do, were taught which batches of ccde are used to accomplish which task and are assigned to slowly build an ASP website using the code/pseudo code given in class.

The Learn through google approch is what were more or less learning for the ASP/User Interface course.
 
Posted by mr_porteiro_head (Member # 4644) on :
 
quote:
Exams coming up no time to "go back to basics" and the exams require the work having actually being done since they open book open notes.
If you don't have the basics and the exams are coming up, then you really do need to go back to basics.
 
Posted by Blayne Bradley (Member # 8565) on :
 
tests are open book, open notes for ASP, what matters is doing the work as the tests are based on the work.
 
Posted by Pegasus (Member # 10464) on :
 
Out of morbid curiosity, and since I know nothing on the subject, what is it that you are coding?
 
Posted by Blayne Bradley (Member # 8565) on :
 
a website where people can buy stock for their franchise im doign vidoe games.
 
Posted by Blayne Bradley (Member # 8565) on :
 
okay by doing what I am doing I can now successfully delete rows it just cant delete multiple rows at once.
 
Posted by TomDavidson (Member # 124) on :
 
Blayne, tell me: do you ever talk to the other students in your class? How do THEY solve these problems?
 
Posted by Blayne Bradley (Member # 8565) on :
 
google or ask other people.
 
Posted by MrSquicky (Member # 1802) on :
 
Blayne,
I don't know what else you've accomplished through this thread, but you've made me regret trying to help you.

Being able to debug a program is pretty much the most important, necessary skill in programming. It is absolutely vital that you get much, much better at it than you have shown if you ever expect to make a living as a programmer. I've lost any interest in trying to help you develop it though.
 
Posted by Blayne Bradley (Member # 8565) on :
 
This isn't about that, this is vb/asp completely different.

This is just 1 tiny problem and while learning to debug programs is a valuable skill and something I am decent at in any other language VB/ASP pisses the hell out of me because it is overly complicated, we were not taught what ANYTHING does and are actively encouraged to figure things out through using google, this is not a course where your high handed and impractical advice of "going back to the basics" would work especially when there are higher priorities, I am under alot of stress to get work done, saying that "you know exctly of what is wrong" and then saying you wont help me at all except through abstract advice that I don't even know how to begin to understand or apply to code is just plain stupid at worst and arrogant at best.

The way I have been taught is shown how by what is wrong, followed by why it went wrong, ending which being shown how to avoid that in the future. The whole throwing me on my own to tackle an issue that I have spent ten hours trying to figure out on my own before coming to Hatrack will not work and will never work.

quote:
but you've made me regret trying to help you.
This is stupidously rude. How the heck do you expect people to treat you seriously when you say such things.
 
Posted by Mucus (Member # 9735) on :
 
Here's a thought: lashing out at the one person that has had the patience to try to walk you through solving your problem, unpaid and unrewarded, is not exactly going to encourage anyone to help you.
 
Posted by MattP (Member # 10495) on :
 
quote:
This is just 1 tiny problem and while learning to debug programs is a valuable skill and something I am decent at in any other language VB/ASP pisses the hell out of me because it is overly complicated
I've only barely played with VB/ASP and it was years ago and not even the .NET flavor which is really its own beast. Despite that, it was quite clear to me how this problem should have been addressed and it never would have occurred to me to ask Hatrack for help. This is not a language problem - it *is* about fundamentals. Index out of bounds errors occur in all major languages and the process for resolving them is going to be the same - debug and learn the API.

No one is trying to give you a hard time just for the sake of giving you a hard time. You're just getting a bunch of momma bird programmers trying to push you out of the nest so you can just use those wings you've already got and fly on your own. It'll be so much more satisfying than getting carried around everywhere.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Either way it doesn't matter I chucked away that line of code, and now voila it works it just doesnt like deleting mutliple rows at once. I don't even know why that line was needed or what it is for how can I begin to debug something if I dont even know what its for? And yes I checked the online documentation and I still do not know what the heck its for.

All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.
 
Posted by TomDavidson (Member # 124) on :
 
Blayne, why not answer my question?
Do you talk to your classmates? How do THEY solve these problems?

What we are describing here, Blayne, is not some "abstract advice." It is the most basic element of what is in many of our opinions the most basic skill required of a programmer.

I am a professional programmer. I do most of my programming in ASP, although I prefer C# to VB these days for my codebehinds. The idea that .NET programming (or the Visual Studio UI) is so hard and so complex that you can't debug it is literally laughable -- and I mean precisely that; if you said that to another programmer, they would laugh you out of the room.

I strongly -- strongly -- advise that you begin to network with other students in your class. You need instruction in some very basic programming principles that, by your description, your professors have neglected. And if you can't count on your teachers to provide them, you're going to need to get them from somewhere before you'll be employable.
 
Posted by Morbo (Member # 5309) on :
 
Tom, he did answer your question.
quote:
Originally posted by Blayne Bradley:
google or ask other people.

But I don't believe those are the only options.
 
Posted by Blayne Bradley (Member # 8565) on :
 
That is indeed what they did, we don't learn how to code in ASP, we learn how to use ASP to make a webbased user interface for an online store, our teacher does not have us try on our own to code what he cannot do himself. Hes advice with my issue is to simply cut down the code to do this:

KeyId = GrivViewRow.Rowindex

Thats it thats all, there may have been a solution to the other line of code but now at least I can finally delete rows.

Now I still have the problem that it wont delete multiple rows at the same time.

And why the heck does the Vista version for VS2005 not have a proper debug mode!?
 
Posted by fugu13 (Member # 2859) on :
 
You are not learning how to make an online store. Any online store you try to make using these methods will be dysfunctional. Neither are you learning to program. You should complain about the quality of the course to your registrar. Heck, I'm near to complaining about the quality of the course to your registrar.
 
Posted by Blayne Bradley (Member # 8565) on :
 
its done in milestones, this is #4, and we gradually add more layers to it, the ability to for example handle thousands of simultanious requests for example will be handled a little latter on.
 
Posted by Nighthawk (Member # 4176) on :
 
quote:
Originally posted by fugu13:
You are not learning how to make an online store. Any online store you try to make using these methods will be dysfunctional. Neither are you learning to program. You should complain about the quality of the course to your registrar. Heck, I'm near to complaining about the quality of the course to your registrar.

I've been down that road before; complaining is a lost cause. It's the reason I never got my degree in Computer Science; I couldn't accept the futility of it all.
 
Posted by King of Men (Member # 6684) on :
 
It does seem somewhat possible that the problem doesn't lie in the actual course.
 
Posted by King of Men (Member # 6684) on :
 
Oh yeah, I meant to answer this.

quote:
Originally posted by Blayne Bradley:
As for those hours we were playing CK at the same time, so no soup for you!

Maybe you were playing CK. I wasn't. If I'd known you were, I'd have done something else with my time. No wonder you had difficulty with the concept, if you weren't even pretending to concentrate.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I am fairly certain we were in one of our sessions KoM and you were guiding me along through it, and then once the session ended we continued via icq.
 
Posted by King of Men (Member # 6684) on :
 
Oh, right. I was actually only counting the ICQ conversation in that three hours.
 
Posted by TomDavidson (Member # 124) on :
 
quote:
And why the heck does the Vista version for VS2005 not have a proper debug mode!?
In order to properly debug code in real-time in VS2005 when running on a Vista machine, it is necessary to run your instance of Visual Studio as an administrator. The easiest way to do this, assuming you have rights, is to right-click on the icon and choose "Run as Administrator" instead of double-clicking on the icon. You can also customize the icon, but any lab system worth its salt would remove that customization when you logged out.
 
Posted by King of Men (Member # 6684) on :
 
In my experience, students do not get admin rights to blow their own noses when it comes to university lab computers. In many cases there are good reasons for this.
 
Posted by steven (Member # 8099) on :
 
"In many cases there are good reasons for this."

Based on the guys I knew who were getting computer degrees, and/or worked in the computer labs in college, yes. More than half of them were worthless hardware-stealing trouble-making vandals. They gave intelligent geeky white guys a very bad name. [ROFL]
 
Posted by Blayne Bradley (Member # 8565) on :
 
riiiiiiiiight I remember now vaguely that my teacher had difficulties and fixed it that way after 3 hours of googling.


And yes I do have admin rights. Advantages of making it to the third year, I also know how to get around nearly ever single firewall and proxy restriction as well.
 
Posted by MrSquicky (Member # 1802) on :
 
quote:
All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.
And that's why I regret wasting my time and energy trying to help you.

You want someone to tell you what to do there. You need to learn how to debug. Right now, you will not be able to hold down or most likely get a programming job.

It would have been much easier for me to tell you what the extremely obvious problem was. I took the time and made the effort to basically lead you by the nose to debug it yourself. All you had to do was actually think about what I was saying and answer the question that I asked and you'd be on the road to learning some valuable stuff.

And all that time, you were just holding back whining "Just tell me what to do!" and weren't going to start thinking for yourself.

I realize that the message of "Stop being so ungrateful, self-centered, and lazy." is going to fly right past you, but maybe you could at least focus on "You need to learn how to debug code."
 
Posted by TomDavidson (Member # 124) on :
 
I'll just say that if you don't know what the phrase "parameter index" means, you will never be a programmer.
 
Posted by King of Men (Member # 6684) on :
 
Um. I must say, I'm not actually totally sure what a parameter index is. It sounds like it should be an index into an array of function parameters, but I can't offhand think of a language that routinely lets you access parameters this way, unless it's Lisp. Conceivably you are being just a touch language-centric, tool-centric, or API-centric there?
 
Posted by King of Men (Member # 6684) on :
 
Oh, wait, I get it now. Thinking too complicated there.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Look here's the issue: there are 3 rows, if I try to dleet the last 2 rows it dleets one, it merges the table so now it tries to delete a row that is nolonger there, I am doing a project all alone that was meant for 2 people to do, in not just this class but in about 3 other classes as well, odd number of people kinda left me out.

In the end my teacher told me to skip it, he'll accept just deleting one row at a time as he designed the course for people to work in 2 person teams not one person trying to handle the entire course load alone, especially when I don't even think a single team managed to get checkboxes to work, everyone else seems to have used buttons rather then chkboxes. I know how to debug, I know how to use the intermediate window, but VB is the only language I work with that uses this many methods, all other languages we were taught we built our own from scratch to learn how to do make our own algooithms.

Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
 
Posted by King of Men (Member # 6684) on :
 
quote:
Originally posted by Blayne Bradley:
[QB]I know how to debug, I know how to use the intermediate window, but VB is the only language I work with that uses this many methods, all other languages we were taught we built our own from scratch to learn how to do make our own algorithms.

No you don't. Conceivably you know how to use a debugger; that is not the same thing. As for the many methods, poor baby. You want to build your own service libraries for every project you udnertake? Good luck to you. If you feel like being productive sometime this century, you'l stop making excuses and start learning how to use an unfamiliar API.

quote:
Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
You are supposed to know that by checking the documentation to see whether it's a string or an int, and not make excuses. Nobody is interested in your excuses. We're willing to help you if you show some slightest hint of a good attitude. You're not doing that.
 
Posted by TomDavidson (Member # 124) on :
 
quote:
I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there?
You could always read the documentation. Or think for a second.

I mean, seriously, give some thought to the underlying reasons a method works. When you return txtbox.Value, what sort of data CAN that be? Why?

You're just trying to plug together a bunch of random pieces according to what your teacher tells you; you aren't actually learning anything about the pieces, or why they work together.

Do you know what an index is yet?
 
Posted by Blayne Bradley (Member # 8565) on :
 
I know what an index is, when did I say I didn't?

code:
Index     Name     Price     Quantity
0 Halo 3 79$ 50
1 Resistence 79$ 50
2 Smash Bros 79$ 50

My problem is that while itll delete the middle 2 rows if there's a fourth, it wont delete rows 1 and 2, because the dt got merged when i deleted the first row.

code:
Index     Name     Price     Quantity
0 Halo 3 79$ 50
1 Smash Bros 79$ 50

So when it goes to look for row 2, its not there anymore.
 
Posted by King of Men (Member # 6684) on :
 
quote:
Originally posted by Blayne Bradley:
All I wanted to know is what was wrong with that line of code because as far as I can tell with the debugger everything is fine, I dont know what parameter index relates to, there is no variable called index. All I wanted was what is wrong and what I could do to fix it not the friggin secret of life.


 
Posted by King of Men (Member # 6684) on :
 
And by the way, if you'd put a moment's thought into this, you'd have realised you can work around the problem by deleting in the opposite order. Took me three seconds to think of.
 
Posted by ricree101 (Member # 7749) on :
 
quote:
Originally posted by King of Men:

quote:
Lets look at it this way, I made a line of code comparing the value of a txtbox and a lbl, how was I supposed to know you are supposed to put val(etc.text) there? To my view a number is a number is a number, didn't know that therwise it simply compares them to see which string is bigger.
You are supposed to know that by checking the documentation to see whether it's a string or an int, and not make excuses. Nobody is interested in your excuses. We're willing to help you if you show some slightest hint of a good attitude. You're not doing that.
This kind of thing is one of the reasons that I think that introductory classes ought to start in assembly and work up from there. Although I'll admit that I might be biased here since this was how I learned programming, I really do believe that it is a great way to learn programming. When you start off really low level, you have to actually consider how all of the data is actually represented in the registers you are working with. Once you get this, it is really easy and intuitive to move on to things like data types and pointers. So even though most programmers are never going to actually use assembly professionally, I think that it helps to create the sort of mindset that makes it easy to understand what is actually going on with the programs you write so that issues like this can be avoided.
 
Posted by Pegasus (Member # 10464) on :
 
I believe that concept is key for being succesful at anything. I, for one, have a real hard time learning how to use a tool if I cannot understand the how and why.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Alright, despite being told that he'ld accept it as it was (deleting 1 row at a time) I as it turns out misunderestimated my own stubburnness so I kept at it.

And voila.

code:
        For Each GridViewRow1 As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)

If CheckBox1.Checked Then
'chkBox = True

'Dim ProductID As String = GridView1.DataKeys(GridViewRow1.RowIndex)("pr_code").ToString
'---Get the database id
KeyId = GridViewRow1.RowIndex
'KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Int32)
'---Use the KeytId to delete from the database.

If KeyId = gt.Rows.Count Then
gt.Rows(KeyId - 1).Delete()
' Larry said its okay to delete one row at a time for now. Iff there's time fix it.
ElseIf KeyId >= gt.Rows.Count Then
gt.Rows(KeyId - KeyId).Delete()
Else
gt.Rows(KeyId).Delete()
' Larry said its okay to delete one row at a time for now. Iff there's time fix it.

End If
End If

Next
GridView1.DataSource = gt
GridView1.DataBind()

I compensated logically for the rows being shunted off to hammer space and it works for anysize datatable for deleting in any possible combination. In a way that wasn't findable with google, you can try to google it, it is 100% mine.
 
Posted by Blayne Bradley (Member # 8565) on :
 
Oh and ignore the Larry comment, he wrote in that before I fixed the code to finally work.
 
Posted by El JT de Spang (Member # 7742) on :
 
I don't know enough about VB to know if it works, but if so Congrats!
 
Posted by fugu13 (Member # 2859) on :
 
gt.Rows(KeyId - KeyId).Delete() ?

Unless there's some weird overloading going on, I think you're doing some rather unnecessary arithemtic.

Also, does the meaning of = change from assignment to comparison depending on context in VB? If not, I'm somewhat confused by the If KeyId = gt.Rows.Count line, and if it does, I'm confused by the line after.
 
Posted by MattP (Member # 10495) on :
 
Also, you follow an "If KeyId = gt.Rows.Count" with an "ElseIf KeyId >= gt.Rows.Count". The '=' in '>=' is superfluous. Just a '>' would do.

Also, have you tested this with a table that has more than a few rows? I'd test at least five rows, with a test run that deletes rows 1,3,5, another run with 1,2,3 and another run with 3,4,5. I don't know VB well enough to say for sure, but I think this is still going to break for more than a few simple 2 or 3-row tests you may have done.
 
Posted by MrSquicky (Member # 1802) on :
 
It will break. The logic is incorrect.

Simple logic game, how do you take two objects - let's say the second and the fifth from the left - out of a line up such that at the time you take them out, they will still be the second and the fifth from the left, respectively?
 
Posted by MattP (Member # 10495) on :
 
Yeah. It won't crash anymore, but it's going to delete the wrong rows in most non-trivial cases.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I've tested it in the following samples.

1 row

3 row

5 row

and random number > 5 rows.

it delets 1 row at a time.

it can delete multiple rows at a time between rows.

and it can delete last 2+ rows at a time without problem.

and it has deleted "all" rows without problem trying differering number of rows (1,3,5,10)

all with unique values like below
code:
0 Halo3 79.99
1 COH 89.99
2 NWN2 79/999

to make sure I know whats being deleted without confusion.

And it works just fine.
 
Posted by Tristan (Member # 1670) on :
 
quote:
Simple logic game, how do you take two objects - let's say the second and the fifth from the left - out of a line up such that at the time you take them out, they will still be the second and the fifth from the left, respectively?
You take them at the exact same time?

Tristan, who has absolutely no idea what he's talking about.
 
Posted by MrSquicky (Member # 1802) on :
 
Tristan,
Sorry, didn't specify. You can only take one at a time. edit: Yes, the answer is really easy. There's no real trick to it.

Blayne,
Hey, if you're happy with it, I don't really care anymore. But it's wrong, and obviously so.
 
Posted by MattP (Member # 10495) on :
 
The thing is, if it *were* working correctly, you'd never need these lines:
code:
If KeyId = gt.Rows.Count Then
gt.Rows(KeyId - 1).Delete()
ElseIf KeyId >= gt.Rows.Count Then
gt.Rows(KeyId - KeyId).Delete()

Their entire purpose is to catch the case when your index has gone past the end of the list. Just saying that you'll delete the last item whenever your index value gets too high is sloppy and dangerous. If your index value does not correspond to an existing row, you should find out why that is happening and fix it.

*EDIT: Eww. It's worse than that. When you go too far (>=) beyond the end, it deletes KeyId-KeyId, or 0. So, in the case where index says 5 but you only have 3 rows, it will delete your first row.

As long as your code doesn't work without that if/else construct, it's not right.
 
Posted by Tristan (Member # 1670) on :
 
Hmm, let's see. I suppose you could assign each item a designation, e.g. a, b, c, d, and e and then specify that you take b and e out of the line-up.

Or you could have an underlying logic that when you you want to take out X and Y it goes something like: take out X; if X < Y, take out Y-1, if X > than Y, take out Y.

*Is bored*
 
Posted by Blayne Bradley (Member # 8565) on :
 
code:
0 Halo3 79.99
1 COH 89.99
2 NWN2 79/999

when i gt.Rows(1).Delete()

code:
0 Halo3 79.99
2 NWN2 79/999

turns into

code:
0 Halo3 79.99
1 NWN2 79/999

so... when i try to delete the last 2 rows.

step 1
code:
0 Halo3 79.99
2 NWN2 79/999

code:
0 Halo3 79.99
1 NWN2 79/999

it tries to delete index 2 when index 2 doesn't exist.
 
Posted by MattP (Member # 10495) on :
 
KOM already provided the right answer, and quite explicitly. Don't iterate from row 1 to row 3. Iterate from row 3 to row 1.
 
Posted by TomDavidson (Member # 124) on :
 
Blayne, I wouldn't expect that to work. If it works, it works only because gt.Rows.Delete() has been modified to also delete the GridView's row at the same time.

KoM gave you the obvious solution to your problem.
 
Posted by MrSquicky (Member # 1802) on :
 
Tristan,
A much simpler rule is, if you need to preserve ordering at the time of removal from the left, start taking things out from the right, i.e. take the fifth from the left first, then the second from the left.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I thouroughly tested it through the debugger and through run time and everything works just fine, I didn't modify Delete, nor does it delete GridView ros at the same time, Gridview is refreshed and fills its rows based on the new datatable until there's no datatable left thus no gridview.

Its works fine, no errors, everything is where they should be.
 
Posted by Tristan (Member # 1670) on :
 
If you do it like that, the terrorists win.
 
Posted by Tristan (Member # 1670) on :
 
Uh, that was to MrSquicky. If you do it like Blayne, it's a splendid victory for thousands of years of ingrained western thought-patterns.
 
Posted by TomDavidson (Member # 124) on :
 
Blayne, try creating ten items. Delete #2, #7, #9, and #10.

Does that work for you?
 
Posted by MattP (Member # 10495) on :
 
quote:
Gridview is refreshed and fills its rows based on the new datatable until there's no datatable left thus no gridview.
Then why do you ever need to check that the index is not greater than the number of rows?

Blayne, think about it. You are telling it to delete the last row whenever the index is equal to the number of rows. Why is the index off by one at that point? If it's off by one then, what's to prevent it from being off by two, three, or ten by the time you've deleted several more rows?

Also, you are telling it to delete the first row whenever the index is greater than the number of rows. How does that ever make sense?

[ November 26, 2007, 03:34 PM: Message edited by: MattP ]
 
Posted by Blayne Bradley (Member # 8565) on :
 
Here is where you are all not actually looking through the logic to see if it makes since because you underestimate me in this case.

I did indeed check deleting odd records and it worked just fine.

code:
0 Halo3 79.99
1 COH 89.99
2 NWN2 79/999
3 Halo2 79.99
4 WOW 89.99

When I Delete a row, the rows merge.

code:
0 Halo3 79.99
1 COH 89.99
2 NWN2 79/999
4 WOW 89.99

like so

code:
0 Halo3 79.99
1 COH 89.99
2 NWN2 79/999
3 WOW 89.99

Thus there is no more index(4) thus when i tried to loop through and went to the last row (in this case 4) to delete it, there was no row and it blew up.

Say I havr 5 rows, and I want to dlete all of them.

It will successfully delete all of the rows until the last row which through merging has become row 0.

Thus if I have 10 rows, have KeyId - KeyId and delete that row.

Thus because there is only ONE row left I automatically delete the first row being the only one.

This was the case of having alot of rows to start off with and deleting all of them.

I go back by 1 only when I am deleting a comparitevly small number of rows that are the end rows.

My solution DOES in FACT work, I have thoroughly tested it, and it works, if you think it doesn't or shouldn't work then welcome to Ornery You are Wrong.
 
Posted by MrSquicky (Member # 1802) on :
 
No, Blayne, your solution doesn't work. The operations that Tom provided will show this to you.
 
Posted by TomDavidson (Member # 124) on :
 
Blayne, do exactly what I describe. Create ten items. Check #2, #7, #9, and #10. Click your "Delete" button.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I did do what Tom showed, works just fine on my end.
 
Posted by MattP (Member # 10495) on :
 
I'd expect that when you went to delete #7, you'd actually delete #8 (because the index is off by one at that point because of the previous delete of #2).

Note that deleting a single row will work. Also, because of your if/else, deleting x number of rows at the end will also work. What I don't expect to work is deleting a row in the middle, then another row in the middle.

Edit: No, deleting at the end won't work either. It'll start deleting rows from the beginning once the index gets high enough. Deleting ALL rows will work though, since you'll always delete the quantity of rows that you are asking to delete, just not the rights ones, but if you delete all rows than it doesn't matter that you aren't deleting the correct ones since your if/else fall back will cause the first or last row to always be deleted once the index goes wonky.

Again, think about it. You already know the index is getting out of sync with the rows, but the only time you deal with that is when the index exceeds the total number of rows. How do you make sure that the index matches the middle rows once you've started deleting some? Why would it be off by one (or more) only when it's on the last row?

[ November 26, 2007, 04:15 PM: Message edited by: MattP ]
 
Posted by MrSquicky (Member # 1802) on :
 
THere's a difference between didn't throw an error and works fine. If you did what Tom described, you'd end up with
3
4
5
6
7
9
10
 
Posted by MrSquicky (Member # 1802) on :
 
Yeah, oops, I took that out, then I looked back and thought "Why did I take 3 out? 1 and 2 would be deleted by the 9 and 10 calls." Silly me.

edit: Which is to say, the list should look like
4
5
6
7
9
10
 
Posted by MattP (Member # 10495) on :
 
Oops. I was having doubts and deleted my post. Sorry about that.
 
Posted by Blayne Bradley (Member # 8565) on :
 
[Embarrassed] I just had to grandstand, I could have just left it alone but nooooooo my 6th sense just had to force me to double check and no of course I just had to stick to my guns I just couldn't stay quiet, fix my code, I just had to make an ass of myself before realizing I was slightly a smigden mistaken.

code:
        Dim count = 0
For Each GridViewRow1 As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)

If CheckBox1.Checked Then
'chkBox = True

'---Get the database id
KeyId = GridViewRow1.RowIndex
'KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Int32)
'---Use the KeytId to delete from the database.

If KeyId = gt.Rows.Count Then
gt.Rows(KeyId - 1).Delete()
ElseIf KeyId > gt.Rows.Count Then
gt.Rows(KeyId - KeyId).Delete()
Else
If count = 0 Then
gt.Rows(KeyId).Delete()
Else
gt.Rows(KeyId - count).Delete()
End If
End If
count = count + 1
End If

Next
GridView1.DataSource = gt
GridView1.DataBind()


 
Posted by MrSquicky (Member # 1802) on :
 
That's still not going to work. And like 4 people have told you exactly how to address this problem.
 
Posted by Blayne Bradley (Member # 8565) on :
 
*blink* okay I am 101% positive that this does the job, as the rows merge it now anticipates it so that it will delete the proper rows regardless of how far they've moved sicne each time I delete something I am 1 row off, thus if I dlete 3 things I am 3 rows off, hence, I use a counter to keep track of how many times I dleted something and adjust what row to dlete accordingly.

I have taken 9 rows, dleted 2, 5, and 7 and I got the correct results only the rows I wanted to dlete were dleted, none were shunted.

Maybe the way those "four" people said would work, but I know that my way also works, code is code there is more then one way to crack a duck.
 
Posted by MrSquicky (Member # 1802) on :
 
And yet, your code does not work.
 
Posted by Blayne Bradley (Member # 8565) on :
 
What are you trying to compile it? It works just fine.
 
Posted by MrSquicky (Member # 1802) on :
 
Huge difference between compiling and working. Using your code will result in rows being deleted that shouldn't be.

Also (and man do you not deserve this and you won't appreciate it), your solution even assuming you tweak it so that it actually works is a very poor one for a common issue. You should learn the proper way to do this that people have been hitting you over the head with because, if you show someone a code sample with this sort of coding in it, you'll mark yourself as a very bad programmer.
 
Posted by TomDavidson (Member # 124) on :
 
quote:
*blink* okay I am 101% positive that this does the job, as the rows merge it now anticipates it so that it will delete the proper rows regardless of how far they've moved sicne each time I delete something I am 1 row off, thus if I dlete 3 things I am 3 rows off, hence, I use a counter to keep track of how many times I dleted something and adjust what row to dlete accordingly.
If I understand you, you intended to add a bit of code (probably after you realized from my example that we were right) that increments every time you delete a row, and then subtracts that from the gridviewrow index to retrieve the new index of the datarow.

(I note, by the way, that the code you've listed above does not actually do this. Your "if" statements here actually prevent this from working the way you would expect. You would be far better off just declaring x to be 0 when you enter the foreach, then incrementing x every pass and deleting x from every index.)

That should work, provided none of your deletes fail for some reason; I'd probably throw up a try...catch around the whole thing just to be sure. That said, it seems remarkably clumsy compared to just -- as everyone else here has suggested -- iterating through the collection from right to left.
 
Posted by MrSquicky (Member # 1802) on :
 
Tom,
3 item list (1, 2, 3), delete 1, delete 3 -> 3
 
Posted by TomDavidson (Member # 124) on :
 
If you did it right, on a ten-item list, it'd work like this:

Delete 1. Correct.
Delete 3-1 (2). Correct.
Delete 8-2 (6). Correct.
Delete 10-3 (7). Correct.

So while Blayne's code doesn't work, and indeed this method is clumsier than it needs to be, you could conceptually subtract one from the index value per item deleted.
 
Posted by Nighthawk (Member # 4176) on :
 
I usually either:

1) Go through the list backwards

...or...

2) Rather than using a "for" or "foreach" loop, use a temporary variable as the position counter, only increment the counter when I'm *not* deleting, and only loop until the counter is greater than the size of the array (no, I'm not going to write code for this now...).
 
Posted by Blayne Bradley (Member # 8565) on :
 
k, i revised the code once again for while it worked for 7, it didnt quite work for 10 as by this point it would go into the KeyId-KeyId if case and screw up my results BUT by expressing that if there's avalid rows past the current row and KeyId > gt.rows.count.

Thus now it goes where its supposed to go and now works even with Toms example.
 
Posted by Dagonee (Member # 5818) on :
 
My preference was "DELETE FROM table_name WHERE primary_key IN (1,3,8,10)".

(Yes, I know that the rowindex isn't the primary key - I would account for that.)
 
Posted by MattP (Member # 10495) on :
 
Yes, it's possible to keep track of how many deletes you've done and update a delta variable as you go along, but that's hard to read, hard to maintain, and unnecessarily complex.

Even if you do decide to go that route, all of those 'if's and 'else's are not necessary. The only 'if' you need is the "If CheckBox1.Checked Then" line. Anything more than that is an indication that you don't understand what exactly is happening.

For instance, why would you need to conditionally subtract count only when it's non-zero? If count is zero, subtracting it has no effect so there is no need for this:
code:
If count = 0 Then
gt.Rows(KeyId).Delete()
Else
gt.Rows(KeyId - count).Delete()
End If

and you can just have this:
code:
gt.Rows(KeyId - count).Delete()

Similarly, if you are properly incrementing the count variable, there is no need for the checks to see if index exceeds count.
 
Posted by Nighthawk (Member # 4176) on :
 
Don't like one SQL statement myself either becuase I need to write more code to maintain the collection array and eventually convert that in to the actual SQL statement.

Pseudo-code... in C#, 'cause I don't have to think about the syntax as much.

code:
int iPos = 0
while ( iPos < gt.Rows.Count )
{
if ( delete row iPos? )
delete row from DB using the unique key
delete "gt.Rows[iPos]" from collection
else
iPos++
}

This accounts for "gt.Rows" shrinking during the delete.
 
Posted by TomDavidson (Member # 124) on :
 
The sad thing about all of Blayne's "fixes" is that, as he fumbles closer and closer to discovering the things we're already telling him, I'm being more and more convinced that at no time has he understood anything we've said to him, or even why his own workarounds are "working."
 
Posted by TomDavidson (Member # 124) on :
 
Actually, it just occurred to me why Blayne might be resisting our suggestions to iterate backwards; he might not know how, since you can't use foreach backwards. He'll need a for loop for that, and his teacher may not have shown him that.
 
Posted by MattP (Member # 10495) on :
 
That could be, but I'd be surprised if they were having them muck with databases before learning for loops. But who knows these days.

[ November 26, 2007, 10:03 PM: Message edited by: MattP ]
 
Posted by Blayne Bradley (Member # 8565) on :
 
I only know how to loop backwards in C.

For (e=0;e<10;e--)
 
Posted by MattP (Member # 10495) on :
 
It's simple in VB

For e = 9 to 0
Next
 
Posted by Nighthawk (Member # 4176) on :
 
quote:
Originally posted by TomDavidson:
Actually, it just occurred to me why Blayne might be resisting our suggestions to iterate backwards; he might not know how, since you can't use foreach backwards. He'll need a for loop for that, and his teacher may not have shown him that.

If his teacher has been doing data binding, collection management and user interfaces before doing a "for loop", then I refuse to believe this is a "programming" course.

*EDIT*

MattP, don't you need a "Step -1"? I admit I haven't done that myself in VB for quite some time...
 
Posted by MattP (Member # 10495) on :
 
quote:
MattP, don't you need a "Step -1"? I admit I haven't done that myself in VB for quite some time...
Not with VB.NET, as far as I know.
 
Posted by ricree101 (Member # 7749) on :
 
quote:
Originally posted by Blayne Bradley:
I only know how to loop backwards in C.

For (e=0;e<10;e--)

Er... check that again. That code right there is going to loop for a lot longer than you probably want it to.

Edit: or, depending on the data type, I suppose it might be shorter than you intend. At any rate, it's likely not doing what you want it to do.
 
Posted by Nighthawk (Member # 4176) on :
 
Actually, I didn't even notice that: your "for" loop in C *is* incorrect...
 
Posted by IanO (Member # 186) on :
 
*still don't get why you are making the row index do double duty as a unique key for the item. Just (in this case, manually create one or) have the db autogenerate a key (in the non-trivial implementation you are working up to). Then when populating the datagrid, set the datagrid row's key to an actual unique key (and not a changing index value). Then just delete the row whose unique key is equal to the one that's selected. This is standard, whether in datagrids, listboxes, dropdowns, etc. That way, the ORDER you delete is completely irrelevant, and you can be sure that the only thing being deleted is an item that has a key that is truly unique and equal to the one you want. (Similar to dagonee's SQL statement)
 
Posted by Dagonee (Member # 5818) on :
 
quote:
Don't like one SQL statement myself either becuase I need to write more code to maintain the collection array and eventually convert that in to the actual SQL statement.
The code to make the SQL statement was a single function call for me.

The big difference was that I was doing stateless* ASP, so I didn't have to coordinate with a UI control at all - I didn't even have that option.

*It wasn't entirely stateless - I had a user context - but we couldn't save anything like a datacontrol to the session.
 
Posted by Blayne Bradley (Member # 8565) on :
 
I know my C was incorrect but I'm too lazy to hit the edit button, ironically the post to explain why i didn't edit it took more calories.
 
Posted by Blayne Bradley (Member # 8565) on :
 
code:
        Dim count = 0
For Each GridViewRow1 As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)

If CheckBox1.Checked Then
'chkBox = True

'Dim ProductID As String = GridView1.DataKeys(GridViewRow1.RowIndex)("pr_code").ToString
'---Get the database id
KeyId = GridViewRow1.RowIndex
'KeyId = CType(GridView1.DataKeys.Item(GridViewRow1.RowIndex).Value, Int32)
'---Use the KeytId to delete from the database.

If KeyId = gt.Rows.Count Then
gt.Rows(KeyId - 1).Delete()
ElseIf KeyId > gt.Rows.Count And (gt.Rows(KeyId - count)(1) = Nothing) Then
gt.Rows(KeyId - KeyId).Delete()
Else
If count = 0 Then
gt.Rows(KeyId).Delete()
Else
gt.Rows(KeyId - count).Delete()
End If
End If
count = count + 1
End If

Next
GridView1.DataSource = gt
GridView1.DataBind()

Revised, this should now work in all cases.
 
Posted by Dagonee (Member # 5818) on :
 
quote:
gt.Rows(KeyId - KeyId).Delete()
This line simply says gt.Rows(0).Delete(). Is that really what you mean here?
 
Posted by fugu13 (Member # 2859) on :
 
You still have silly things like gt.Rows(KeyId - KeyId).Delete() in your code.

Blayne, what's 1-1? What's 5-5? What's x-x? What's KeyId - KeyId?

And most of your code is still extraneous (and based on incorrect logic). I think its wrong, too.

I think the only reason it might work is because you've added lots of qualifiers to unnecessary statements to make them not trigger except when they're equivalent of what you really need, which is silly.

Btw, what does gt.Rows(KeyId - count)(1) get you?
 
Posted by fugu13 (Member # 2859) on :
 
Bleh, Dagonee beat me to it.
 
Posted by MattP (Member # 10495) on :
 
Um, wow. Remember what I said before, Blayne - even with your current scheme all of those if/else constructs are completely unnecessary. It's like adding 2 + 2 like this:

2 + 4 - (3 * 27) + (2 * 51) - 5^2 + 2

You need an If to check if the checkbox is checked. That's it. Everything else is baling wire and duct tape. This whole thing should be 10-15 lines of code, not 30.
 
Posted by TomDavidson (Member # 124) on :
 
*sigh* If we must....

code:
 
Dim count = 0
For Each GridViewRow1 As GridViewRow In GridView1.Rows
'---Look at each checkbox here
CheckBox1 = CType(GridViewRow1.FindControl("chkSelector"), CheckBox)
If CheckBox1.Checked Then
gt.Rows(GridViewRow1.RowIndex - count).Delete
count = count + 1
End If
Next
GridView1.DataSource = gt
GridView1.DataBind()



[ November 27, 2007, 12:45 PM: Message edited by: TomDavidson ]
 
Posted by MattP (Member # 10495) on :
 
Fish giver! [Wink]
 
Posted by Blayne Bradley (Member # 8565) on :
 
Ah, now i see what you mean. [Eek!]
 
Posted by King of Men (Member # 6684) on :
 
You know, a few days ago I was idly paging through Joel's archives, and I came across this article,which contains among much wisdom the words

quote:
I know a few superstar programmers who could crank out a Fortran compiler by themselves in one week, and lots of programmers who couldn’t write the code to print the startup banner if they had six months.
For some reason I thought he was exaggerating. I can't imagine what I was thinking. Although cheer up, Blayne, google "Paula Bean" and realise that you haven't yet hit rock bottom.
 
Posted by Blayne Bradley (Member # 8565) on :
 
code:
package test;

public class paulaBean {

private String paula = "Brillant";

public String getPaula() {
return paula;
}
}

Smrthel.
 
Posted by Nighthawk (Member # 4176) on :
 
quote:
Originally posted by King of Men:
You know, a few days ago I was idly paging through Joel's archives, and I came across this article,which contains among much wisdom the words

quote:
I know a few superstar programmers who could crank out a Fortran compiler by themselves in one week, and lots of programmers who couldn’t write the code to print the startup banner if they had six months.
For some reason I thought he was exaggerating. I can't imagine what I was thinking. Although cheer up, Blayne, google "Paula Bean" and realise that you haven't yet hit rock bottom.
Thank you for that article. I recently was the applicant and went through a similar interview process at a major medical company in the area, and although it was awkward at the time I now understand the reasoning behind it. And I agree with all of it.

And I've met my share of Paulas...
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2