Passing values to jSP on button click

Hello
I have multiple delete buttons on the JSP page. What i want is to get the value as to which delete button was clicked. I am not sure if i shld have multiple names for the buttons. For now all have the same name since its inside a while loop.
Also i want to confirm that the user really wants to delete the field. But i dont know how can i pass the value as well as the function at the same time through the onClick function.
I tried type="hidden" for the field value and onClick="function" (where function is a javascript function that confirms if the user does want to delete the field). BUt in this case with type = hidden i get all the values corresponding to the field.
Any pointers?
heres the sample HTML code if it helps.. this one is just to show how the screen looks like. The actual JSP has the while loop.. which is also pasted below
<HTML>
<HEAD><TITLE>File Format Management</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var errMsg = "";
function confirmDelete(frm)
     var deleteSure = confirm("Are you sure you want to delete the fileType?");
     if (deleteSure)
            frm.submit();
     return deleteSure
//-->
</SCRIPT>
</head>
<body>
<BR>
<CENTER>
<TABLE border="1" cellpadding="0" cellspacing="0" marginwidth=0 marginheight=0>
  <TR class="titlebar">
    <TD align="center">File Format Management</TD>
  </TR>
  <TR bgcolor="#cccccc">
    <TD>
<B>File Types:</B>
<p>The following file types are defined for this project.</p>
<div align="center">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr><td>Filetype��</td><td># of fields��</td><th></th><th></th></tr>
<tr><td>Demographics</td><td align="center">5</td><td><input type="submit" value="Edit"></a></td><td align="right"><input type="submit" value="Delete"></a></td></tr>
<tr><td>Clinical</td><td align="center">17</td><td><input type="submit" value="Edit"></td><td align="right"><input type="submit" value="Delete"></td></tr>
<tr><td>MS</td><td align="center">9</td><td><input type="submit" value="Edit"></td><td align="right"><input type="submit" value="Delete"></td></tr>
<tr><td>HLA</td><td align="center">20</td><td><input type="submit" value="Edit"></td><td align="right"><input type="submit" value="Delete"></td></tr>
<tr><td>SNP</td><td align="center">18</td><td><input type="submit" value="Edit"></td><td align="right"><input type="submit" value="Delete"></td></tr>
<tr><td colspan="4"><input type="submit" value="Add new filetype..."></td></tr>
</table>
</div>
<p align="center"><input type="submit" value="Return"></p>
</td>
</tr>
</table>
</body>
</html>
//actual while loop in JSP
<table cellpadding="3" cellspacing="0" border="0" width="100%">
            <tr class="titleitem"><td>Filetype��</td><td># of fields��</td><th></th><th></th></tr>
            <% if ((!fileTypesFormats.equals(null)) && (fileTypesFormats.size() > 0))
                    Iterator keyIter = fileTypesFormats.entrySet().iterator();
                    while (keyIter.hasNext())
                        Map.Entry CurrentEntry = (Map.Entry) keyIter.next();
                        String formatNos = CurrentEntry.getKey().toString();
                        String fileTypeName = CurrentEntry.getValue().toString();
                        count++;
             %>
                   <tr class="<%=htmlObj.getClassString(count)%>">
                     <td><input type="hidden" name="filetypeName" value="<%=fileTypeName%>"><%=fileTypeName%></td>
                     <td align="center"><%=formatNos%></td>
                     <td><input type="button" value="Edit" name="editBtn" onclick="location.href='edit_delete_filetype_format.jsp'"></a></td>
                     <td align="right"><input type="button" name="deleteBtn" value="Delete" onclick='confirmDelete(this.form)'></a></td>
                   </tr>
             <% } } %>
                    <tr class="<%=htmlObj.getClassString(count)%>"><td colspan="4"><input type="button" value="Add new filetype..." onclick="location.href='edit_delete_filetype_format.jsp'"></td></tr>
        </table>

Thanx for your help praveen
I appreciate that.. but i misguided you. I am sorry abt that
I want the value of the field beside the delete box to be passed to the Server side scripting.
so if u see the html page u see something like this
"Demographics 4 Edit Delete "
"Clinical 3 Edit Delete"
//note edit and delete are buttons
Of this when the user clicks on Delete I want the jsp to pass Demographics value to the JSP.
Right now it will pass all the values like "Demographics Clinical" . I probably have to give different names to the buttons...lets c
Thanx for u r help

Similar Messages

  • Passing value to jsp page by clicking a hyperlink

    I have a hyperlink in a jsp page1. The hyperlink is for another jsp page2. I have a string value in JSP page1, which I want to pass to jsp page2 when user clicks the hyperlink. Can anyone tell me what will be the suitable way to do this? Thanks.

    here's the source to two very simple jsps that do what you want..
    <HTML>
    <HEAD>
    <TITLE>
    ForwardValue
    </TITLE>
    </HEAD>
    <BODY>
    <H1>
    Go To GetValue.jsp
    </H1>
    </BODY>
    </HTML>
    <HTML>
    <HEAD>
    <TITLE>
    GetValue
    </TITLE>
    </HEAD>
    <BODY>
    <H1>
    <%= request.getParameter("value") %>
    </H1>
    </BODY>
    </HTML>

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • Passing values between jsp and php

    hi there, is it possible to pass values between jsp and
    php? i really need to find out the way if there is
    any. thanks in advance
    -azali-

    Yes, there are a few ways to do this.
    1) Think about using Cookies.
    2) Maybe use a Redirect passing the values in the Query string.
    3) Retain the data in a repository in the back end.
    4) Using Hidden fields within your pages.
    I am sure you can use these Idea's for a base to develop other methods on how to pass values back and forth from JSP -> PHP and vice versa.
    -Richard Burton

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • Passing value from JSP to JSPDynPage onclick of link

    Hi,
    I have extracted a value in the JSP page and i want to send this value back to the JSPDynPage on click of a link(the link is dependent on the value).
    How can i do that?

    hi Sujoy,
    you can pass values by using beans and display the passed data in a new jsp page.
    firstly create a jsp page,that accepts user data,say for example i am placing a text box and a button,
    next,create a jspdyn page---
    private final static int INITIAL_STATE = 0;
        private final static int FINAL_STATE = 1;
        private int state = INITIAL_STATE;
        private final static String BEAN_KEY="nameBean";
        public void doInitialization(){
          IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
          IPortalComponentContext ctxt=request.getComponentContext();
          displayNameBean mybean = new displayNameBean();
          ctxt.putValue(BEAN_KEY,mybean);
    public void doProcessAfterInput() throws PageException {
             InputField myInputField = (InputField) getComponentByName("user_name");
    if (myInputField != null) {
    IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
    IPortalComponentContext ctxt = request.getComponentContext();
                 displayNameBean mybean1=(displayNameBean)ctxt.getValue(BEAN_KEY);
                   mybean1.setName(myInputField.getValueAsDataType().toString());
        public void doProcessBeforeOutput() throws PageException {
          switch (state){
               case INITIAL_STATE:
               this.setJspName("loginPage.jsp");
               break;
               case FINAL_STATE:
               this.setJspName("successloginPage.jsp");
               break;
        public void onButtonClick(Event event) throws PageException {
             state=FINAL_STATE;       
    finally display this value in a new jsp page as follows--
    <jsp:useBean id="nameBean" scope="application" class="NewProject.bean.displayNameBean" />
    <%@ taglib uri= "tagLib" prefix= "hbj"%>
    <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
    <hbj:textView
         id="welcome_note"
         design="HEADER2">
         <% 
         welcome_note.setText
         (nameBean.getName());
         %>
    as simple as that!!
    regards
    SwarnaDeepika
    P.S:Please reward points for helpful answers.

  • Passing values between jsp pages

    Hi all,
    I am a newbie to jsp. I am trying to pass value from one jsp to another.
    Let me post the code here and make my point clear. I have 3 jsp pages and am trying to get the value into my 3rd page that was in the first page.
    This is my Test.jsp page:
    <%@page contentType="text/html"%>
    <html>
    <head><title>Test JSP Page</title></head>
    <body>
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    Testing.. JSP Page
    <FORM action='Response.jsp' method="POST">
    <input type='Text' name='get_name'>
    <input type="submit" value="Click Me">
    </FORM>
    </body>
    </html>
    This is my response.jsp page:
    <%@page contentType="text/html"%>
    <%@page import = "sun.jdbc.rowset.CachedRowSet" %>
    <html>
    <head><title>Response Page</title></head>
    <body>
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    Thank you... <%=request.getParameter("get_name") %>
    // I want to pass this get_name to my next page, but since request.getParameter returns an object and not a string, how will I capture the value and pass it to my next page.
    </body>
    </html>
    The 3rd jsp page is:
    <%@page contentType="text/html"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    // I am trying to get the value of the name here in this page.
    <%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
    <%-- <jsp:getProperty name="beanInstanceName" property="propertyName" /> --%>
    </body>
    </html>
    Your help is appreciated.
    Thanks

    Hi,
    Thanks for the reply, it works. I was wondering whether this is an efficient way of doing this. What I want to do further is to setup a connection to a database and use the value I got from my previous page to query the DB and get the results and display.
    I have see some code in the java website and a lot of people do by writting a bean /class(believe bean is just a class) and then importing it and do the things that way. I have good knowledge of OO and Java as a language and would definitely love to do it this way.
    What i think i am missing is the basic idea to doing this way. So if you could let me know how to do this using java classes I would really appreciate it. If its too much to explain can u point to some good source(URL's) that explain's this. I have searched on this and all i find is code with no good explaination.
    Thanks a lot

  • Pass value between JSP pages

    I would like to pass values between pages.
    I don't want showing up on the url. Ex: some.jsp?param=value
    I don't feel it's safe.
    It's not coming from form either....
    How can I hide the value and pass it to next page?
    I want to pass the value when the user click on a hyperlink
    Thanks In Advance.
    Message was edited by:
    Theepan

    Client side information is never safe no matter what you do. If the values don't end up in the url, they are always present SOMEWHERE in the html content.
    If you don't want the values to end up in the url, rework the page so it DOES do a post form submit. You could turn the hyperlink into a javascript call that submits the form for you.

  • Passing value from JSP to scriptlet

    Hi
    I am trying to find a way to pass a value from jsp to the scriptlets, i.e.
    <c:set var="testValue" value="123" />
    <%
    System.out.println(testValue);
    %>
    the above code just demonstrates what I was trying to achieve, by passing the value from the jsp into the scriptlet.
    Can someone tell me if there's an easy way to do this?
    Thank you.

    Note, using scriptlet code on your page is generally something to be avoided. 99% of what you should be doing on a JSP page can be done with EL/JSTL. If you can't do it with EL/JSTL then it probably belongs in a servlet/bean.
    I always aim for 100% scriptlet free jsp pages.
    Having said that, I can still answer your question: EL attributes are stored in the scope - page, request, session, application
    ${testValue} is equivalent to pageContext.findAttribute("testValue").
    The <c:set> tag example doesn't specify a scope, so therefore you could get it like this:
    <c:set var="testValue" value="123" />
    <%
    String testValue = (String)pageContext.getAttribute("testValue");
    System.out.println(testValue);
    %>alternatively exploit the feature of the useBean tag that creates a scriptlet variable:
    <c:set var="testValue" value="123" />
    <jsp:useBean id="testValue" type="java.lang.String"/>
    <%
    System.out.println(testValue);
    %>Note that the EL variable and the Scriptlet variable are initially pointing at the same String.
    But changing the string in scriptlet code will change the value it is pointing at, while leaving the EL variable untouched.
    If you have a List in scope, and sharing it between EL and scriptlet variables then any changes to the list would be reflected because they both point at the same List object.
    cheers,
    evnafets

  • Servlet passing values to JSP and ClasscastException

    I am using weblogic 5.1 to run my Servlets.
              I want to know when I forward from a servlet to a JSP how do I pass
              values especially Java Objects (Sometimes Objects of User written Java
              classes).
              Uptil now I have been putting all values in the session from where the
              JSP picks them up, but somehow I have a feeling that this is not the
              right way.
              In a code I am putting a Java Object (It contains two attributes of
              Java.util.Vector type) in the session so that the JSP to which I am
              forwarding it to can use it I have put my class in the ServletClasses.
              Intertestingly it runs well till the contents of the Vector are changed.
              As the contents of the vector are changed, it throws ClassCastException
              The StackTrace is as follows:
              java.lang.ClassCastException
              at
              jsp_servlet._select_95_account_95_profile._jspService(_select_95_account_95_pro
              file.java, Compiled Code)
              at weblogic.servlet.jsp.JspBase.service(JspBase.java, Compiled
              Code)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java,
              C
              ompiled Code)
              at
              weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.j
              ava:143)
              at
              com.logistics.optistopasp.servlet.AccountSelectServlet.doPost(AccountSelectServ
              let.java, Compiled Code)
              at
              com.logistics.optistopasp.servlet.AccountSelectServlet.doGet(AccountSelectServl
              et.java:35)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java,
              C
              ompiled Code)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.j
              ava, Compiled Code)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.j
              ava, Compiled Code)
              at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextMan
              ager.java, Compiled Code)
              at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java,
              Compile
              d Code)
              at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java,
              Compiled Code
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java,
              Compiled Code)
              Can anybody please Help!!!!.
              Thanks
              Pankaj
              

    Only can confirm your finding - the jsp is using a different class loader to the servlet that originally instantiated the object. There's the rub. I haven't figured out yet how to fix that. I can get the classloader but don't know how to get the runtime to use that class loader to perform cast.
              

  • Servlet passing Values to JSP

    I want to know when I forward from a servlet to a JSP how do I pass
              values especially Java Objects (Sometimes Objects of User written Java
              classes).
              Uptil now I have been putting all values in the session from where the
              JSP picks them up, but somehow I have a feeling that this is not the
              right way.
              Suppose my servlet is forwarding to a jsp . What should it do in case an
              exception happens in the servlet and wants to forward it to the jsp.
              Putting the Exception object in the session is an alternative but I
              wonder that is the best approach.
              If someone knows a better way od doing it, please help.
              Pankaj
              

    You could probably use setAttribute
              ..before forwarding the control to JSP.
              req.setAttribute("message", "Hello, world");
              ServletContext app = getServletContext();
              RequestDispatcher disp;
              disp = app.getRequestDispatcher("Dispmessage.jsp");
              Cheers,
              Naggi
              pankaj wrote:
              > I want to know when I forward from a servlet to a JSP how do I pass
              > values especially Java Objects (Sometimes Objects of User written Java
              > classes).
              > Uptil now I have been putting all values in the session from where the
              > JSP picks them up, but somehow I have a feeling that this is not the
              > right way.
              > Suppose my servlet is forwarding to a jsp . What should it do in case an
              > exception happens in the servlet and wants to forward it to the jsp.
              > Putting the Exception object in the session is an alternative but I
              > wonder that is the best approach.
              > If someone knows a better way od doing it, please help.
              >
              > Pankaj
              

  • Passing value from JSP to Action in Struts

    Hi,
    I am populating JSP page with rows retrieved from the database and
    represented as a List of Beans in forEach loop:
    <c:forEach var="list" items="${OperationsForm.OperationsList}">
    <c:choose>
    <c:when test="${list.isCompleted =='Y'}" >
    <td width="100">Completed</td>
    <td width="100"> </td>
    </c:when>
    <c:otherwise>
    <td width="100">Pending</td>
    <td width="100"><input type="image" onclick="
    rowId=value; form.action='action.do?command=notify'"
    value="${list.OperationId}" />
    </td>
    </c:otherwise>
    </c:choose>
    </tr>
    </c:forEach>
    Have hidden field: html:hidden property="rowId" value="-1"/>
    User is clicking the button corresponding to one of the rows
    and I need to pass the value of that rowId to the Action class, so it does
    something in the database [action completed]
    Now how do I pass it , is that the right way of doing it with calling
    request.getSession().getAttribute(rowId) in the Action class ?
    As of now I am getting Javascript error "Object doesn't support this
    property or method", complaining about rowId=value;
    Using Struts 1.3
    Please help !
    TIA,
    Oleg.

    So what you are saying is that I should add rowId here:
    <input type="image" onclick="form.action='action.do?command=notify&rowId='
    ${list.OperationId}"/> , correct ?
    I am not sure that it will work, especially with Struts tag.
    I will probably try something like:
    <html:submit onclick="form.action='action.do?command=notify'" value="${list.OperationId}">
    I am relatively new to Struts, so now sure what will work or not and how to do it better. How do I catch the submitted value in the Action in either of these 2 cases, via action.getSession().getProperty("rowId") /
    action.getSession().getProperty("submit") ?
    I would probably do it as a URL rather than changing the action of the form.I will have to create a new action anyway to process that row [which is sending user e-mail regarding that row data/event].
    Is the id the only thing you have to pass in?
    Or do you need other values from the screen?Selected rowId is probably the only thing I care about, can access values from the Form in Action.
    Thank you,
    Oleg.

  • Passing values to jsp from html..

    Hi all,
    I have a jsp containing a selection list and need to pass the value to the java segment of the jsp. When reserching this, I've found some info where an html page was created, an initial jsp was saving the info (or bean was used) and then a third jsp displayed the data (using buttons). This is too many steps and I'm needing a way for the same jsp to display containing the selected option (simulating a refresh with the post when the drop down list is used). Is redirecting while setting and getting attributes all at once feasible/possible or is there a better direction or work around for this?
    Thanks in advance,
    Geoff-

    I would think submitting the page to itself, and setting hidden fields to signal that it is a resubmission, may be the way to go. If the new information being displayed is minimal, JavaScript may also work, by setting up an empty <div> or <span> and setting the innerHTML or innerText properties. The advantage of the JavaScript solution is it would be quicker, having the client do all the processing, but it also browser dependant.

  • How to pass value from JSP to Javascript?

    I want to pass 2 integers to Javascript to do checking? How can I do that?

    Well, it is very simple, Follow these steps.
    1. Have a form with fields
    2. On submit validate the form using javascript
    3. If the javascript returns false do not submit the form
    4. if the javascript returns true submit the form
    5. The destination jsp page will handle the db operations.
    1. <form name="frm1" action="dbcheck.jsp">
    <input type="text" name="txt1">
    <input type="button" value="submit" onClick="return validate();">
    </form>
    put the above piece of code in the <body> tag
    2. Upon submit the js function validate() will be called :
    <script language="javascript">
    function validate() {
    if(document.frm1.txt1.value="") {
    alert("enter text");
    return false;
    else {
    document.frm1.submit(); // i am not sure whether the () after submit is required or not
    put the above piece of code in the <head> tag.
    3. Now when the submit happens, the control goes to the dbcheck.jsp
    this is dbcheck.jsp:
    <%
    String str = (String) request.getParameter("txt1");
    ------other db operations go here --------
    %>
    "txt1" is the field name of the textbox from the form u previously submitted.
    all da best

  • MVVM Light Bind value to list on button click

    I am trying to build an simple universal app and I have followed the MVVM light setup. So far everything has fallen in place. Now I have a button and a listview on the same page. What I am trying to achieve is when I click on the button I want the list
    view to show values. I have the list view bound to an observable collection and the button bound to RelayCommand. When I click the button the relay command is executing and returning values which I add to the observable collection, but myview is not getting
    updated. when i directly create object in my design mode and in runtime the view is updating properly. Please provide any suggestion.
    Code Section
    View
    <Page
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:CorrectMetroCardFare"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ViewModel="using:CorrectMetroCardFare.ViewModel"
        x:Class="CorrectMetroCardFare.MainPage"
        mc:Ignorable="d"
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
        DataContext="{Binding Main, Mode=OneWay, Source={StaticResource Locator}}">
        <Grid Height="640" Margin="0,0.333,0,-0.333" VerticalAlignment="Top">
            <TextBlock x:Name="title" Text="Metro Card Fare"  Margin="0,10,0,603"/>
            <TextBox x:Name="txtCurrentValue" InputScope="Number" PlaceholderText="Enter your Current Balance" Margin="0,53,0,0" Text="{Binding CurrentBalance, Mode=TwoWay}"/>
            <Button Content="Show Fares" HorizontalAlignment="Left" Margin="96,113,0,0" VerticalAlignment="Top" Command="{Binding ShowFaresCommand, Mode=OneWay}" CommandParameter="{Binding
    CurrentBalance}" />
            <ListView x:Name="nbc" SelectionMode="Single" Margin="10,182,10,150" ItemsSource="{Binding Charges}">
                <ListView.Resources>
                    <DataTemplate x:Key="FareTemplate">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding AmountToRecharge}" TextAlignment="Right" Grid.ColumnSpan="4"
    Margin="0,0,-28,0" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource TextStyleLargeFontSize}"></TextBlock>
                            <TextBlock Text="{Binding BonusAmount}" TextAlignment="Right" Margin="118.333,0,-128.333,0"
    Grid.Column="3" FontSize="{StaticResource TextStyleLargeFontSize}"/>
                            <TextBlock Text="{Binding NewBalance}" TextAlignment="Right" Margin="118,0,-229.333,0"
    Grid.Column="3" FontSize="{StaticResource TextStyleLargeFontSize}"/>
                            <TextBlock Text="{Binding NumberofRides}" TextAlignment="Right" Margin="298,0,-308.333,0"
    Grid.Column="3" FontSize="{StaticResource TextStyleLargeFontSize}"/>
                        </Grid>
                    </DataTemplate>
                    <ItemsPanelTemplate x:Key="FaresPanelTemplate">
                        <VirtualizingStackPanel Orientation="Vertical"></VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                    <DataTemplate x:Key="headerTemplate">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="90" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="Amount to Recharge" Grid.Column="0" TextWrapping="WrapWholeWords" FontFamily="{StaticResource
    PivotHeaderItemFontFamily}" FontSize="{StaticResource ContentControlFontSize}"/>
                            <TextBlock Text="Bonus Amount" Grid.Column="1" TextWrapping="WrapWholeWords" FontFamily="{StaticResource
    PivotHeaderItemFontFamily}" FontSize="{StaticResource ContentControlFontSize}"/>
                            <TextBlock Text="New Balance" Grid.Column="2" TextWrapping="WrapWholeWords" FontFamily="{StaticResource
    PivotHeaderItemFontFamily}" FontSize="{StaticResource ContentControlFontSize}"/>
                            <TextBlock Text="Number of Rides" Grid.Column="3" TextWrapping="WrapWholeWords" FontFamily="{StaticResource
    PivotHeaderItemFontFamily}" FontSize="{StaticResource ContentControlFontSize}"/>
                        </Grid>
                    </DataTemplate>
                </ListView.Resources>
                <ListView.HeaderTemplate>
                    <StaticResource ResourceKey="headerTemplate"/>
                </ListView.HeaderTemplate>
                <ListView.ItemsPanel>
                    <StaticResource ResourceKey="FaresPanelTemplate"/>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <StaticResource ResourceKey="FareTemplate"/>
                </ListView.ItemTemplate>
                <ListView.DataContext>
                    <ViewModel:MainViewModel/>
                </ListView.DataContext>
            </ListView>
        </Grid>
    </Page>
    View Model
         /// <summary>
                    /// Sets and gets the DayList property.
                    /// Changes to that property's value raise the PropertyChanged event.
                    /// </summary>
                    public ObservableCollection<BonusChargesValue> Charges
                        get
                            return _charges;
                        set
                            if (_charges == value)
                                return;
                           // RaisePropertyChanging(ChargesListPropertyName);
                            _charges = value;
                            RaisePropertyChanged(ChargesListPropertyName);
                    public RelayCommand ShowFaresCommand
                        get;
                        set;
              /// <summary>
                    /// Initializes a new instance of the MainViewModel class.
                    /// </summary>
                    public MainViewModel()
                        if (IsInDesignMode)
                            // Code runs in Blend --> create design time data.
                           // BonusChargesValue bnc = new BonusChargesValue();
                            _charges = new ObservableCollection<BonusChargesValue>();
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 10.0, BonusAmount = 5, NewBalance = 15, NumberofRides = 5 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 12.0, BonusAmount = 6, NewBalance = 17, NumberofRides = 6 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 14.0, BonusAmount = 7, NewBalance = 19, NumberofRides = 7 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 16.0, BonusAmount = 8, NewBalance = 21, NumberofRides = 8 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 18.0, BonusAmount = 9, NewBalance = 23, NumberofRides = 9 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 10.0, BonusAmount = 5, NewBalance = 15, NumberofRides = 5 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 12.0, BonusAmount = 6, NewBalance = 17, NumberofRides = 6 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 14.0, BonusAmount = 7, NewBalance = 19, NumberofRides = 7 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 16.0, BonusAmount = 8, NewBalance = 21, NumberofRides = 8 });
                            _charges.Add(new BonusChargesValue { AmountToRecharge = 18.0, BonusAmount = 9, NewBalance = 23, NumberofRides = 9 });
                        else
                            // Code runs "for real"
                            Charges = new ObservableCollection<BonusChargesValue>();
                            ShowFaresCommand = new RelayCommand(GetValues, () => { return true; });
                          //  ShowFares = new RelayCommand(() =>
                               // Words = new string(Words.ToCharArray().Reverse().ToArray());
                            //_charges = new ObservableCollection<BonusChargesValue>();
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 10.0, BonusAmount = 5, NewBalance = 15, NumberofRides = 5 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 12.0, BonusAmount = 6, NewBalance = 17, NumberofRides = 6 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 14.0, BonusAmount = 7, NewBalance = 19, NumberofRides = 7 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 16.0, BonusAmount = 8, NewBalance = 21, NumberofRides = 8 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 18.0, BonusAmount = 9, NewBalance = 23, NumberofRides = 9 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 10.0, BonusAmount = 5, NewBalance = 15, NumberofRides = 5 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 12.0, BonusAmount = 6, NewBalance = 17, NumberofRides = 6 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 14.0, BonusAmount = 7, NewBalance = 19, NumberofRides = 7 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 16.0, BonusAmount = 8, NewBalance = 21, NumberofRides = 8 });
                            //_charges.Add(new BonusChargesValue { AmountToRecharge = 18.0, BonusAmount = 9, NewBalance = 23, NumberofRides = 9 });
                    private void GetValues()
                        CalculateMetroFare cmcf = new CalculateMetroFare();
                        if (!string.IsNullOrWhiteSpace(CurrentBalance))
                            var chr = cmcf.Add2ExistingCard(Convert.ToInt32(CurrentBalance));
                            foreach (BonusChargesValue bncv in chr)
                                Charges.Add(bncv);
                        }`enter code here`
                       // return _charges;
    VAravind ---------------------------------------------------------------------------------------------------------------------------------- Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post
    has been useful to you. Blog
    VAravind ---------------------------------------------------------------------------------------------------------------------------------- Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post
    has been useful to you. Blog

    I am not getting error but the Listview is not getting updated after the relay command
    VAravind ---------------------------------------------------------------------------------------------------------------------------------- Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post
    has been useful to you. Blog

Maybe you are looking for

  • Problem with Mail in Snow Leopard

    I have iOS10.6.8.  My mail program keeps recovering an email that I sent a week ago. It included photos.  I delete them, but they just keep returning.  Worse, no new emails from that account appear.  I can send, but not receive unless I go to my iClo

  • WLST Libraries

    I have a number of WLST scripts which all use a number of common functions I've written such as: common.py: import sys import os import shutil import re def offline_createManagedServer(Name, Port, ListenAddress):      cd('/')      create(Name, 'Serve

  • ADDT Code issues with w2k8 IIS7/FastCGI?

    Has one else experienced any issues with the ADDT Dynamic List code not working with IIS7/FastCGI on w2k8? Fresh install of 2k8 ent, w/iis7 and fastcgi running. Most applications work just fine but there semes to be issues with pages that have ADDT d

  • Need serial number #2

    I know I need to contact Apple but my question is who and how? Telephone, email what?

  • Since updating to iOS 8.2  my iphone 6 plus battery drains very fast, does not have the same performance

    the iOS 8.2 drains my battery life for the iphone 6 plus, i need some tricks to have more efficency