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

Calling ListView ItemUpdating event when a button outside the control is clicked?

P: 5
I have a listview control in which I had replaced all the ItemTemplate labels with TextBoxs. I also have a command button on the page, when the button is clicked I am able to retreive the text in all the TextBoxes one by one by running a For..next loop. After reading the textboxes content I want to fire the ItemUpdating event for each row so that I can update all the rows at once.

I have the following code in the button_click event, but it does nothing
Expand|Select|Wrap|Line Numbers
  1.     Dim idcount As ListViewItem
  2.         Dim i As Int32
  3.         Dim ei As New ListViewUpdateEventArgs(i)
  4.         For Each idcount In ListView1.Items
  5.             ei.NewValues("Name") = DirectCast(ListView1.Items.Item(i).FindControl("NameLabel"), TextBox).Text
  6.             i = i + 1
  7.         Next
Is it not possible to update all the records at once through the above approach

I also tried another approach listed below with a light change, but with no results...
Expand|Select|Wrap|Line Numbers
  1.     Dim idcount As ListViewItem
  2.         Dim i As Int32
  3.         Dim ei As New ListViewUpdateEventArgs(i)
  4.         For Each idcount In ListView1.Items
  5.             ListView1_ItemUpdating(i, ei) '<-----
  6.             i = i + 1
  7.         Next
Please help
Jan 15 '09 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
Why don't you just save the names into a list and create a function, called Update, that accepts the list as a parameter and updates the rows?

The ItemUpdating event is a ListView event. The ListView raises this even when an item is being updated. Your code can handle this event but your code cannot raise it.

It would make more sense just to create a method that does the updating rather than try and raise an event which you are going to handle in a method anyways.
Jan 20 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.