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

access to datalist value

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
I see. I'll try to use DataKeys then. Thanks for your help, Marshal.
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.