Solved

access value of listview

Posted on 2014-01-27
10
313 Views
Last Modified: 2014-01-28
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
Comment
Question by:metropia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 

Author Comment

by:metropia
ID: 39814244
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39814773
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
 

Author Comment

by:metropia
ID: 39815069
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
Technology Partners: 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!

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 39815498
Change that line to

Dim item As ListViewItem = e.Item
0
 

Author Comment

by:metropia
ID: 39815604
let me try that :)
0
 

Author Comment

by:metropia
ID: 39815615
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
 

Author Comment

by:metropia
ID: 39815627
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
 

Author Comment

by:metropia
ID: 39815769
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39816316
Cool. So problem sorted?
0
 

Author Comment

by:metropia
ID: 39816501
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question