Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

access value of listview

how can I access the value of a field of a list view control?

I am trying like this:

Dim myRecipeStepsHistory = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.lvRecipeSteps.FindControl("Recipe_Id").ToString())


But I get an error estating that Object needs to be instantiated.

Please any help would be great. Thank you.
0
metropia
Asked:
metropia
  • 7
  • 3
2 Solutions
 
metropiaAuthor Commented:
I also tried:

           Dim tb As TextBox = DirectCast(Me.lvRecipeSteps.FindControl("Recipe_Id"), TextBox)
            Dim x As String = tb.Text

but get:
Object reference not set to an instance of an object.

on line:
            Dim x As String = tb.Text

Any ideas?
0
 
CodeCruiserCommented:
You can find the item using listview.Items property and then use FindControl on this item to get the specific control value. Example here

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.items(v=vs.110).aspx
0
 
metropiaAuthor Commented:
I tried your recommendation but I get a message: NewEditIndex is not a member of System.....

error
Can you see what I am missing?

Thank you very much.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CodeCruiserCommented:
Change that line to

Dim item As ListViewItem = e.Item
0
 
metropiaAuthor Commented:
let me try that :)
0
 
metropiaAuthor Commented:
that took the error away. how would I access a field on the listview after that?
when it is in update/ edit mode.

thank a lot.
0
 
metropiaAuthor Commented:
I did this:

        If e.CommandName = "Update" Then
            Dim myContext As New OLTPEntities
            Dim item As ListViewItem = e.Item
            Dim tbx As TextBox = DirectCast(item.FindControl("Recipe_IdLabel"), TextBox)

Open in new window


But it tbx contains Nothing.

The field I am trying to access to when on Edit:

<td class="RefineRecipe_Steps_Cells"><asp:Label ID="Recipe_IdLabel" runat="server" Text='<%# Eval("Recipe_Id") %>' /></td>

Open in new window

0
 
metropiaAuthor Commented:
this works:

            Dim item As ListViewItem = e.Item

            Dim tbx As TextBox = TryCast(item.FindControl("Recipe_IdTextBox"), TextBox)
            Dim strRecipeId As String = String.Empty

            strRecipeId = tbx.Text

Open in new window

0
 
CodeCruiserCommented:
Cool. So problem sorted?
0
 
metropiaAuthor Commented:
Somehow. I granted you the points because your comment helped me to fix the issue of this question. Unfortunately it also made me realized there were other errors needing fixing. Because of that I created another question I hope you can take a look to.

Thanks a lot. :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now