Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datalist - how to specify what to display question

Status
Not open for further replies.

sonya9879

Programmer
Jun 18, 2004
147
CA
Hello,

I have a navigation bar in a datalist and I am trying to be able to specify what I want to display depending on the value i pass through a variable. Let me explain you what I have so far:

I have a simple navigation file (i.e. navigation.ascx)
with this :

<ASP:DATALIST id="MyDataList_Navigation" runat="server" AutoGenerateColumns="false" width="100%">
<itemtemplate>
<table cellSpacing="0" cellPadding="0" border="0" width="100%">
<% If sname = "al1" Then %>
<tr>
<td><img src="arrowdown.gif"><A class="shadow" href="<%# DataBinder.Eval(Container.DataItem, "URL") %>"><%# DataBinder.Eval(Container.DataItem, "Name") %></A></td>
</tr>
<% Else %>
<tr>
<td><img src="arrowup.gif"><A class="blue" href="<%# DataBinder.Eval(Container.DataItem, "navbarURL") %>">&nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "navbarName") %></A></td>
</tr>
<% End If %>
</table>
</itemtemplate>
</ASP:DATALIST>

then I have different files where I call the navigation bar like this:

<MyTest:Navigation id="Navigation1" sname="al1" runat="server"></Facility:LeftBar>

<MyTest:Navigation id="Navigation1" sname="al2" runat="server"></Facility:LeftBar>

etc.. you get the idea

but now I am thinking that I have several different sections in my navigation bar and I cannot say <% If sname = "al1" Then %> for each one, that just wouldn't make sense. Does anyone knows an alternative way to what I am trying to achieve? each section calls the navigation.ascx and pass a variable (sname) value to it. I just need to be able to compare that value with the datalist result that comes from the database and if it matches then I show an arrowdown. Apparently supposed to be a simple thing :(
 
pass the sname value to the query that is binding the datalist???

Known is handfull, Unknown is worldfull
 
hi vbkris thanks for your comments but how I actually do that if the value of sname is passed in the actual tag in each page I call the header?
 
i am passing the value of sname to datamember in my datalist and i can get that value now. now I guess I should do a comparison within the datalist using a function?
 
nope, can i have the code where u bind the datalist (In the ASCX file)???

Known is handfull, Unknown is worldfull
 
hi again,

i have actually done the following now:

<ASP:DATALIST id="MyDataList_Navigation" runat="server" AutoGenerateColumns="false" width="100%" datamember='<# sname %>'>
<itemtemplate>
<table cellSpacing="0" cellPadding="0" border="0" width="100%">
<tr><td><%# RenderSections(DataBinder.Eval(Container.DataItem, "ID"),DataBinder.Eval(Container.DataItem, "VAL") %></td></tr>
</table>
</itemtemplate>
</ASP:DATALIST>

My code in the ascx is:

MyDataList_Navigation.DataSource = getnavigation()
MyDataList_Navigation.DataBind()

then I have the RenderSections function as follow:

Function RenderSections(byval ID as integer, byval val as string)
Dim imgDisplay AS String = ""
If ID = MyDataList_Navigation.DataMember Then
imgDisplay="<img src...arrow down"
Else
imgDisplay="<img src...arrow up"
End If

All works fine now, I get the arrow down when it matches but now I want to pass another value, VAL which will specify if I can actually display that section or not.

If val = myvalsec1 then
return imgDisplay & "... HERE I WANT TO GET THE VALUE DataBinder.Eval(Container.DataItem, "URL") and DataBinder.Eval(Container.DataItem, "NAME") "
ElseIf val = myvalsec2 then
return imgDisplay & "... HERE I WANT TO GET THE VALUE DataBinder.Eval(Container.DataItem, "URL") and DataBinder.Eval(Container.DataItem, "NAME") "
End If

I tried to use panels but didnt; work because when it doesnt match val with my own variable (myvalsec1, etc.) then it hides for all the sections. Am I confusing you here now? :( sorry!
 
rather than using:
<# DataBinder.Eval(Container.DataItem, "navbarName") %>

try this:
<# CallMe(DataBinder.Eval(Container.DataItem, "navbarName")) %>

function CallMe (TheName)
response.write(TheName)
end function

thats how u get the DataBinder Value to a function...

Known is handfull, Unknown is worldfull
 
i am already doing something similar in my last attempt to get this working
 
oops, got sleepy, hold on let me take a better look at it.

>>All works fine now, I get the arrow down when it matches but now I want to pass another value, VAL which will specify if I can actually display that section or not


and i am guessing that it is this VAL that is "al1" etc? and it is this VAL that u want to compare with the Eval columns???

Known is handfull, Unknown is worldfull
 
i got it working by passing the 2 extra values to the function itself, so i dont need to try to bind the datalist again as i pass the values from the datalist and now works fine. Probably this is a different way to do it but it seems to work fine. thanks vbkris for follow up with me.

i.e

Function RenderSections(byval ID as integer, byval val as string, byval URL as string, byval NAME as string)
...
If val = myvalsec1 then
return imgDisplay & url & name
ElseIf val = myvalsec2 then
return imgDisplay & url & name
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top