473,396 Members | 2,036 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,396 software developers and data experts.

access to datalist value

Hi

Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid
Dim str = MyDataGrid.Cell(0).tex

I would like something like this
Dim str = DataBinder.Eval(MyDatalist.Items(count).DataItem, "customerId")
but it doesn't work.
Nov 18 '05 #1
4 8272
Hi Jenn,
You can access the Datalist values of a row like this :
In the ItemDataBound event of the DataList,
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

object row_items=e.Item.DataItem;

// If you have a column called customerId,

object items = e.Item.DataItem;

string str1=Convert.ToString(DataBinder.Eval(row_items,"c ustomerId"));

}

Additional info:

You can find the controls in thge ItemTemplate of your datalist :

In ItemDataBound event :

eg :
((LinkButton)e.Item.FindControl("LinkB")).CommandA rgument=e.Item.ItemIndex.T
oString();

This will set the commandargument for the Linkbutton,
LinkB.

The above code is in C#.

You can easily convert it into VB.NET.Let me know if you have any
problems.

Hope this helps.

Marshal Antony

..NET Developer

http://www.dotnetmarshal.com



"jenn" <an*******@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
Hi,

Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid: Dim str = MyDataGrid.Cell(0).text

I would like something like this:
Dim str = DataBinder.Eval(MyDatalist.Items(count).DataItem, "customerId")
but it doesn't work.

Nov 18 '05 #2
Hi Marshal

Thanks for the reply, but I'm looking at accessing the datalist values from outside of the ItemDatabound event. So what I did was to loop through the datalist like this

dim i as int=
while i<Mydatalist.items.coun

dim str = MyDatalist.Items(i).DataItem("customerid") <-- this does not wor

end whil

In datagrid you can easily do that like this

Dim str = MyDataGrid.Items(i).Cell(0).tex

Is there a way to do this with datalist

----- Marshal Antony wrote: ----

Hi Jenn
You can access the Datalist values of a row like this
In the ItemDataBound event of the DataList
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType =
ListItemType.AlternatingItem)

object row_items=e.Item.DataItem

// If you have a column called customerId

object items = e.Item.DataItem

string str1=Convert.ToString(DataBinder.Eval(row_items,"c ustomerId"))

Additional info

You can find the controls in thge ItemTemplate of your datalist

In ItemDataBound event

eg
((LinkButton)e.Item.FindControl("LinkB")).CommandA rgument=e.Item.ItemIndex.
oString()

This will set the commandargument for the Linkbutton
LinkB

The above code is in C#

You can easily convert it into VB.NET.Let me know if you have an
problems

Hope this helps

Marshal Anton

..NET Develope

http://www.dotnetmarshal.co



"jenn" <an*******@discussions.microsoft.com> wrote in messag
news:C0**********************************@microsof t.com..
Hi
Anyone knows how to access to a value of a row in a datalist. Somethin
like this in datagrid Dim str = MyDataGrid.Cell(0).tex
I would like something like this Dim str = DataBinder.Eval

but it doesn't work


Nov 18 '05 #3
Hi Jenn,
In DataList ItemTemplate used for how each item will be rendered.
For example,
<ItemTemplate>
Customer <%#
Convert.ToString(DataBinder.Eval(ContainerDataItem ,"customerid"))%>
<ItemTemplate>

You can access datalist values out side of Itemdatabound..
You can use DataKeys collection to retrieve
information from the datalist.
For example if you have a delete event handler,
Dim str1 As
String=DataList1.DataKeys(e.Item.ItemIndex)

Here is a link on MSDN on DataList web server control.
http://msdn.microsoft.com/library/de...classtopic.asp

Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com


"jenn" <an*******@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hi Marshal,

Thanks for the reply, but I'm looking at accessing the datalist values from outside of the ItemDatabound event. So what I did was to loop through
the datalist like this:
dim i as int=0
while i<Mydatalist.items.count

dim str = MyDatalist.Items(i).DataItem("customerid") <-- this does not work
end while

In datagrid you can easily do that like this:

Dim str = MyDataGrid.Items(i).Cell(0).text

Is there a way to do this with datalist?

----- Marshal Antony wrote: -----

Hi Jenn,
You can access the Datalist values of a row like this :
In the ItemDataBound event of the DataList,
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

object row_items=e.Item.DataItem;

// If you have a column called customerId,

object items = e.Item.DataItem;

string str1=Convert.ToString(DataBinder.Eval(row_items,"c ustomerId"));
}

Additional info:

You can find the controls in thge ItemTemplate of your datalist :

In ItemDataBound event :

eg :
((LinkButton)e.Item.FindControl("LinkB")).CommandA rgument=e.Item.ItemIndex.T oString();

This will set the commandargument for the Linkbutton, LinkB.

The above code is in C#.

You can easily convert it into VB.NET.Let me know if you have any
problems.

Hope this helps.

Marshal Antony

..NET Developer

http://www.dotnetmarshal.com



"jenn" <an*******@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
> Hi,
>> Anyone knows how to access to a value of a row in a datalist.
Something like this in datagrid:
> Dim str = MyDataGrid.Cell(0).text
>> I would like something like this:

> Dim str = DataBinder.Eval(

> but it doesn't work.


Nov 18 '05 #4
I see. I'll try to use DataKeys then. Thanks for your help, Marshal.
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Celine | last post by:
I'm using a datalist to display a picture and a dropdownlist associated to it. When clicked the picture should display a larger picture ( this is working fine). When the user has selected a...
0
by: Renato Neves | last post by:
My problem is simple, i have a datalist control with some controls inside of EditTemplate (the problem is the same in the DataGrid). I want to have access to this controls, using javascript, but i...
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
1
by: zino | last post by:
is there a way to access an HTML control embeded inside a datalist ? I need to format the datalist depends on specific condition while databinding ( on ItemDataBound) <datalist runat=server>...
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...
1
by: Gary Frank | last post by:
I added a couple of labels and a button to a Datalist control called "dlSignIn" by adding them to the Item template. The labels are bound to a dataset column. Program code gets executed in the...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
4
by: matt | last post by:
hello, i have a datagrid w/ a TemplateColumn in it, like so: <asp:TemplateColumn HeaderText="Select"> <ItemTemplate> <asp:CheckBox ID="chkSelected" Runat="server"/> </ItemTemplate>...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.