Datallist with 2 different <itemtemplates>

  • Thread starter Thread starter aaapaul
  • Start date Start date
A

aaapaul

Depending on a variable (language), I want to use a different
<itemtemplate> in my Datalist.

code like this:

page_load
select case strLanguage
case "english"
"use itemtemplate1" 'without prices
case "german"
"use itemtemplate2" 'with prices
end select

How can I realize this ?

I tried to make it with <SelectedItemTemplate> and
If strSprache = "englisch" Then MyList.SelectedIndex = 1,
but this work not for alle entries, just for one.

Do you have any idea?

thanks
aaapaul
 
I would suggest you to use the ItemDataBound event of the datalist and
define what will be displayed when a current item is bound
then you will have only one ItemTemplate
and all work will be to determine the values to show

Regards
Martin
 
Hello Martin !

I do this:

.... OnItemDataBound="OnItemList" ...

Protected Sub OnItemList(ByVal objSource As Object, ByVal objArgs As
DataListItemEventArgs)
MyList.SelectedIndex = 1 ??? ' This doesnt work correctly.
End Sub

But what command have I to use ?

thanks
aaapaul
 
Hi aaapaul,

As i mensioned in my previous post you use ItemDataBound event to define
what will be displayed when .net framework operate with a current item from
the datalist
for example: when you have 3 items in the datalist the ItemDatabound is
called every time before sending information for what will be displayed for
every item

so in this context you CAN Not do like MyList.SelectIndex = 1, because the
selected index is already set
but what you CAN DO is to set properties like

If e.Item.ItemIndex = 1 Then
'color the grid cell in red
End If

I don't know if you visualization of the data is formated different for evey
language ( mean not the format of date but the position of controls ) but
what is different between these 2 items ( in your case )
the other way of perform a change like you want to is to create 2 web user
control and depending ot the language value show the one or the other

Regards
Martin
 
Back
Top