access to datalist value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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,"customerId"));

}

Additional info:

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

In ItemDataBound event :

eg :
((LinkButton)e.Item.FindControl("LinkB")).CommandArgument=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
 
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,"customerId"))



Additional info

You can find the controls in thge ItemTemplate of your datalist

In ItemDataBound event

eg
((LinkButton)e.Item.FindControl("LinkB")).CommandArgument=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
 
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/d...fsystemwebuiwebcontrolsdatalistclasstopic.asp

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




jenn said:
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:
 
Back
Top