473,386 Members | 1,997 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,386 software developers and data experts.

Get data value(s) from a DataList control

I've tried various ways to get data value(s) from a DataList control (with same results for ListView and FormView). These are my attempts:

Expand|Select|Wrap|Line Numbers
  1.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim dli As DataListItem
  3.         For Each dli In DataList1.Items
  4.             Dim theValue As String = CType(DataList1.FindControl("AttendeeMailLabel"), Label).Text
  5.             MsgBox(theValue)
  6.         Next
  7. End Sub
With result: Object reference not set to an instance of an object

I've also tried:

Expand|Select|Wrap|Line Numbers
  1.         Dim itemValue As String
  2.         Dim lvi As ListViewItem
  3.         For Each lvi In ListView1.Items
  4.             itemValue = lvi.Text
  5.             'also tried, with same result: itemValue = lvi.SubItems(0).Text
  6.             MsgBox(itemValue)
  7.         Next
  8. End Sub
With result: "'Text' is not a member of System.Web.UI.WebControls.ListViewItem"

Any ideas/suggestions?

This is the script:

Expand|Select|Wrap|Line Numbers
  1.     <form id="form1" runat="server">
  2.     <div>
  3.  
  4.     </div>
  5.     <br />
  6.     <br />
  7.     <asp:ListView ID="ListView1" runat="server" DataKeyNames="AttendeeID" 
  8.         DataSourceID="SqlDataSource1">
  9.         <ItemTemplate>
  10.             <tr style="">
  11.                 <td>
  12.                     <asp:Label ID="AttendeeEmailLabel" runat="server" 
  13.                         Text='<%# Eval("AttendeeEmail") %>' />
  14.                 </td>
  15.             </tr>
  16.         </ItemTemplate>
  17.         <AlternatingItemTemplate>
  18.             <tr style="">
  19.                 <td>
  20.                     <asp:Label ID="AttendeeEmailLabel" runat="server" 
  21.                         Text='<%# Eval("AttendeeEmail") %>' />
  22.                 </td>
  23.             </tr>
  24.         </AlternatingItemTemplate>
  25.         <EmptyDataTemplate> ... </EmptyDataTemplate>
  26.         <InsertItemTemplate> ...  </InsertItemTemplate>
  27.         <LayoutTemplate> ... </LayoutTemplate>
  28.         <EditItemTemplate> ... </EditItemTemplate>
  29.         <SelectedItemTemplate>
  30.             <tr style="">
  31.                 <td>
  32.                     <asp:Label ID="AttendeeEmailLabel" runat="server" 
  33.                         Text='<%# Eval("AttendeeEmail") %>' />
  34.                 </td>
  35.             </tr>
  36.         </SelectedItemTemplate>
  37.     </asp:ListView>
  38.     <asp:Button ID="Button1" runat="server" Text="Button" />
  39.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  40.         ConnectionString="<%$ ConnectionStrings:ActivitiesConnectionString %>" 
  41.         SelectCommand="SELECT [AttendeeEmail], [AttendeeID] FROM [Attendees] WHERE ([ActivityID] = @ActivityID)">
  42.         <SelectParameters>
  43.             <asp:Parameter DefaultValue="43" Name="ActivityID" Type="Int32" />
  44.         </SelectParameters>
  45.     </asp:SqlDataSource>
  46.     </form>
Feb 12 '09 #1
1 8809
Expand|Select|Wrap|Line Numbers
  1. Dim theValue As String = DirectCast(dli.FindControl("AttendeeMailLabel"), Label).Text
Thanks to Qin Dian Tang - MSFT at forums.asp.net

-Bradley
Feb 14 '09 #2

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

Similar topics

1
by: Yoshitha | last post by:
hi I have datalist control in my ASP.NET application the problem here is i have used a textbox with multiline true propertly when i enter data like "fdjsfhjksdhfjsdfhsdjhfsdfhsdjfhsd...
0
by: Anil Kulkarni | last post by:
Hi Folks, My Situation(program requirement): I have datalist control and having Datagrid inside each ItemTemplate column of datalist control.I am fetching data from "Product" & "StyleDetails"...
3
by: Colin Young | last post by:
I'm having a bit of a problem with my DataList when I try to update from the user's input. I've included relevant excerpts at the end of this message. In the UpdateCommand code, the...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
0
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
5
by: Stephanie_Stowe | last post by:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for years, and am now in a position to do ASP.NET. I am in the stumbling around until I get my bearings phase. I hope you will...
4
by: regaliel | last post by:
I am using a datalist control (dlist_myfavorites) and this control is bound to a sqldatareader source. Datalist is basicly populated by the following sp. CREATE PROCEDURE ( @mguid as...
3
by: webserverpete | last post by:
I am new to ASP.NET in general, but I do have experience with classic ASP. I am using a DataList control with a hidden value to submit to a different page, however I do not know how to get to that...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
0
by: diff | last post by:
I am having trouble preventing a bound source from updating using event-driven validation. There is a very nice article on MSDN explaining this;...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.