• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

Display text based on condition in datalist

Hello all,

I need help displaying text in a datalist based on a condition.   In the text I need to call a subroutine that will reopen this case.  I got the text part down but I don't know how to call the subroutine.

So far,  I created a function that I call using the following:

<asp:Label ID="lblStatus" Text='<%#ReturnStatus(Container.DataItem("Closed"), Container.DataItem("Pending"), Container.DataItem("CloseDate"), Container.DataItem("ClosedUser"))%>' runat="server" />

Here's my function:

Function ReturnStatus(ByVal intClosed As Integer, ByVal intPending As Integer, ByVal strCloseDate As String, ByVal strClosedUser As String)
        Dim strMessage As String = ""
       
        If intClosed = 1 Then
             strMessage = strMessage & "<strong>This case has been closed.  Click "
            strMessage = strMessage & "here"  <b>' here being a link to the subroutine</b>
            strMessage = strMessage & " to re-open.</strong>"
        end if

  Return strMessage
End Function
0
dakinegeek
Asked:
dakinegeek
  • 3
  • 2
1 Solution
 
David H.H.LeeCommented:
Dear dakinegeek,
You can make the function accessible use public or protected type.
eg:
Public Function ReturnStatus(ByVal intClosed As Integer, ByVal intPending As Integer, ByVal strCloseDate As String, ByVal strClosedUser As String) as string
Btw, you can put everything in code-behind instead of put together with aspx code
eg:
Sub Page_Load
  if not ispostback then
    loaddata
  end if
End Sub

Sub loaddata
  lblStatus.Text=ReturnStatus(....) 'your invoked function here..
end sub
0
 
SammyCommented:
Container.DataItem returns an object type while your function is expecting an integer
you can either cast your object in the function call like using Ctype(Container.DataItem("Closed"),Integer) -Note I am not exactly sure about VB syntaxes
another way is to have your function expect a objects instead of integers and do the casting in the method body
0
 
dakinegeekAuthor Commented:
Hey guys,

Thanks for your efforts in answering my question.  Although, I think I've been misunderstood.

Within the strMessage, I don't know how to put a LinkButton to a subroutine called Reopen.

StrMessage would return the following ("Here" being the link):

"This case has been closed.  Click Here to re-open"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
David H.H.LeeCommented:
Dear dakinegeek,
Do you want to call subroutine in client script?
eg:
strMessage = strMessage & "<strong>This case has been closed.  Click "
strMessage = strMessage & "<a href='javascript:void(0);' onclick='javascript:yourfunctionhere();'>Here</a><b>' here being a link to the subroutine</b>
 strMessage = strMessage & " to re-open.</strong>"

<script language="javascript">
function yourfunctionhere(){
 alert('Your function go here...');
}
</script>

Is that what you want to solve? Please let us know if you need more assistance.
0
 
dakinegeekAuthor Commented:
x com,

It would have to be a server side script.  In the subroutine, I'll be running an SQL Update query to reopen the case.

Thanks,
0
 
David H.H.LeeCommented:
Dear dakinegeek,
You can use ajax to solve this problem.
eg:
Namespace Yournamespace
Public Class Test
        Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   AjaxPro.Utility.RegisterTypeForAjax(GetType(Test))
end sub

<AjaxPro.AjaxMethod()> Public Sub CallYourFunction(ByVal strItem As string)
  'running SQL Update, amend your code & function here...
End Sub

end class
end namespace
       
'call from ASPX
function yourfunctionhere(){
  var response = Yournamespace.Test.CallYourFunction('yourparameter');
      
if (response.error != null){                                    
return;
}      
else{alert('Sorry, update error...')}      
}

More details regarding how to use AJAXPro, you can refer here:
http://www.ajaxpro.info/
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now