Welcome to WebmasterWorld Guest from 34.228.115.216

Forum Moderators: ocean10000

Message Too Old, No Replies

if else statements

ok - here's another question from me

     
4:11 pm on Jun 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


I am querying my database on the code behind page (aspx.vb) and displaying information on the aspx page like this, for example

<%#Utils.CheckForNull_Text2(Container.DataItem("USER"))%>

The above displays a name such as --> Bob
All is good here

But I want to add some logic to the page and in my head I know what I want to do with Classic ASP experience, but being new to ASP.net, some things are not coming along easily.

So on the .aspx page, I want to do something like

<%if #Utils.CheckForNull_Text2(Container.DataItem("USER")) = "Bob" then%>

lbl.text = "blah blah"

<%else%>
'nothing
<%end if%>

I am not sure how to have the proper syntax here --> <%if #Utils.CheckForNull_Text2(Container.DataItem("USER")) = "Bob"


Please help!

Thanks
4:17 pm on June 21, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


You should put all of it into the code behind:

if Utils.CheckForNull_Text2(Container.DataItem("USER")) = "Bob" then
lbl.text = "blah blah"
else
'nothing
end if
5:19 pm on June 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


hmm
Thanks!
6:40 pm on June 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'Container' is not declared.

Source Error:

Line 85: Try
Line 86:
Line 87: If Utils.CheckForNull_Text2(Container.DataItem("ROLE_LEVEL1")) = "YES" Then
Line 88: strQuery = "SELECT * FROM tblCalendar where ROLE_LEVEL1 = 'YES' AND DATE_DISPLAY > '" & strcurrmonth & " /01/" & strcurrentyear & "' AND DATE_DISPLAY < '" & strcurrmonth & "/" & strdaysinmonth & "/" & strcurrentyear & "' ORDER BY [DATE_DISPLAY] ASC"
Line 89:
7:01 pm on June 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


Sorry - So my question is how do I declare "Container"? What did I do wrong?
11:23 am on June 22, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


Sorry, I didn't look at your code properly, I see that you are binding against a List of Data, is that correct?

If you're using something like a DataList, Repeater or Datagrid you can use the RowDataBound event, here is an example for a GridView Control

 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' Check Value
If DataBinder.Eval(e.Row.DataItem, "USER") = "Bob" Then
Dim lbl As Label = e.Row.FindControl("lbl")
If Not lbl Is Nothing Then
lbl.Text = "blah blah"
End If
End If
End If
End Sub
7:56 pm on June 22, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


I am getting errors. Do you have working code for the code behind page and aspx page I can examine and sub in my info?
8:13 pm on June 22, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


OK, the code above seems to be OK for a Gridview, but what about a datalist? This part gets an error -->

Handles GridView1.RowDataBound

Particularly the "RowDataBound" word.
8:24 pm on June 22, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


OK, the code above seems to be OK for a Gridview, but what about a datalist? This part gets an error -->

Handles GridView1.RowDataBound

Particularly the "RowDataBound" word.

Thats because a DataList control has a slightly different event, ItemDataBound, and also your DataList most likely does not have the Id 'GridView1'.

Try playing around with the ItemDataBound Event, it works a little like RowDataBound, so you will have access to the underlying Data.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members