Rowid in datatable

Hi,
How to get teh rowid in datatable?
When i view teh html, i see that the textfield id is constructed as "datatable_id:0:textfield_id", "datatable_id:1:textfield_id", etc. I want to know the rowid so that i can pass it to some javascript.
Is there any api that'll give me this?
Thanks,

Use HtmlDataTable#getRowIndex(). Here is an use example: [http://balusc.blogspot.com/2006/06/using-datatables.html#AddRowNumbers].

Similar Messages

  • How do I get the rowid or the DataModel from a DataTable inside a DataTable

    Hi,
    I have a simple application which I cannot get to work.
    I have two entity classes: Parent and Child.
    I want to create a page which lists all of the Parents, and in a column of the Parent row has an inner dataTable which displays the Children of the Parent. I then want to click on the Child and link to a view of that Child. What is happening is that I cannot resolve which child was clicked inside my row. I don't seem to be able to get the datamodel for the List children, so it always defaults to the first child in the list.
    Goal: drill down to a specific child from a list of parents with a sublist of children belonging to each parent.
    I have tried creating a new method called prepareChildView() in ParentController like this below but it always returns the first child. I figure I need to create the DataModel earlier but cannot figure out how to do this. Perhaps the auto generated pattern makes it difficult to achieve what I want to - not sure.
    public String prepareChildView() {
            current = (Parent)getItems().getRowData();
            DataModel d = new ListDataModel(current.getChildren());
            Child child = (Child)d.getRowData();
            //child is always the first child!
            return "\children\View";
        }I may be going about this completely wrong so am open to suggestions. I am using JSF2, Glassfish3.0.
    Parent.java
    @Entity
    public class Parent implements Serializable {
        @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
        private List<Child> children;
        public List<Child> getChildren() {
            return children;
        public void setChildren(List<Child> children) {
            this.children = children;
    }Child.java
    @Entity
    public class Child implements Serializable {
        @ManyToOne
        @JoinColumn(name = "parent")
        private Parent parent;
        public Parent getParent() {
            return parent;
        public void setParent(Parent parent) {
            this.parent = parent;
    }ParentFacade and ChildFacade are auto generated from NetBeans, as are ParentController and ChildController.
    ParentController:
    Code doen't fit in the post.
    List.xhtml
    <h:form styleClass="jsfcrud_list_form">
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListParentEmpty}" rendered="#{parentController.items.rowCount == 0}"/>
                <h:panelGroup rendered="#{parentController.items.rowCount > 0}">
                    <h:outputText value="#{parentController.pagination.pageFirstItem + 1}..#{parentController.pagination.pageLastItem + 1}/#{parentController.pagination.itemsCount}"/> 
                    <h:commandLink action="#{parentController.previous}" value="#{bundle.Previous} #{parentController.pagination.pageSize}" rendered="#{parentController.pagination.hasPreviousPage}"/> 
                    <h:commandLink action="#{parentController.next}" value="#{bundle.Next} #{parentController.pagination.pageSize}" rendered="#{parentController.pagination.hasNextPage}"/> 
                    <h:dataTable value="#{parentController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Id"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Name"/>
                            </f:facet>
                            <h:outputText value="#{item.name}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Children" />
                            </f:facet>
                            <h:dataTable value="#{item.children}" var="child" >
                                <h:column>
                                    <h:commandLink action="#{parentController.prepareView}" value="#{child.name}" />
                                </h:column>
                            </h:dataTable>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value=" "/>
                            </f:facet>
                            <h:commandLink action="#{parentController.prepareView}" value="#{bundle.ListParentViewLink}"/>
                            <h:outputText value=" "/>
                            <h:commandLink action="#{parentController.prepareEdit}" value="#{bundle.ListParentEditLink}"/>
                            <h:outputText value=" "/>
                            <h:commandLink action="#{parentController.destroy}" value="#{bundle.ListParentDestroyLink}"/>
                        </h:column>
                    </h:dataTable>
                </h:panelGroup>
                <br />
                <h:commandLink action="#{parentController.prepareCreate}" value="#{bundle.ListParentCreateLink}"/>
                <br />
                <br />
                <h:commandLink value="#{bundle.ListParentIndexLink}" action="/index" immediate="true" />
            </h:form>

    Hi,
    It will help to resolve your issue:
        public String processChildView(){
            UIComponent component = null;
            String  componentId = null;
            Parent parent = null; //Bean class
            Child child = null; //Bean Class
            FacesContext context = FacesContext.getCurrentInstance();
            UIViewRoot root = context.getViewRoot();
            String childView = "childView";
            //Parent Table UIData
            componentId = "parentChildTable";
            component = findComponent(root, componentId);               
            UIData parentTable = (UIData) component;
            //Child Table UIData
            componentId = "childTable";
            component = findComponent(root, componentId);               
            UIData childTable = (UIData) component;
            //Perform Parent Child operation
            if(parentTable != null && childTable != null){
                if(parentTable.getRowData() instanceof Parent){
                    //Get Parent Object from parentTable
                    parent = (Parent) parentTable.getRowData();
                    //Get child object by parent object using childTable's Row Index
                    parent = (Parent) parentTable.getRowData();
                    child = (Child) parent.getChild().get(childTable.getRowIndex());
                    System.out.println("Parent Name " + parent.getName() + "Child Name " + child.getName());
            return childView;
        //Utility method to get component by passing component id in requested view
        public static UIComponent findComponent(UIComponent c, String id) {
             if (id.equals(c.getId())) {
               return c;
             Iterator kids = c.getFacetsAndChildren();
             while (kids.hasNext()) {
               UIComponent found = (UIComponent) findComponent((UIComponent)kids.next(), id);
               if (found != null) {
                 return found;
             return null;
      } Regards,
    Manish Paliwal
    "Life is beautifull."

  • Input validation in datatable

    Hi all,
    I have a datatable displaying some records and allowing for each record to press a link to to something with that line. I am however facing problems with the field validation. Here's what I have:
    <t:dataTable style="width: 100%" id="tfopts" binding="#{quoteOptions.freeFormOptionTable}" value="#{quoteOptions.unselectedFreeFormOptions}" var="option">
         <t:column width="70%">
              <h:inputText style="width: 98%" value="#{option.description}" />
         </t:column>
         <t:column style="white-space:nowrap" width="15%">
              <h:inputText style="width: 100%" value="#{option.catalogPrice}">
                   <f:convertNumber/>
              </h:inputText>
         </t:column>
         <t:column style="white-space:nowrap" width="15%">
              <a4j:commandLink action="#{quoteOptions.addFreeFormOption}" value="#{msg.options_addoption}" reRender="selopts,tfopts" />
         </t:column>
    </t:dataTable>Now, I need to make sure that the description is not empty when hitting the commandLink. I have tried by setting the required attribute, but then it's set for all rows, which I do not want.
    Alternatively I approached it via Javascript, but it occurred to me that I don't know the id of the field on the row where the commandlink is clicked.
    Can anyone help me out with this?
    Thanks

    tombatore wrote:
    Now, I need to make sure that the description is not empty when hitting the commandLink. I have tried by setting the required attribute, but then it's set for all rows, which I do not want.This should work:required="#{!empty param['formId:dataTableId:rowId:commandLinkId']}"The 'rowId' part can be obtained from UIData#getRowIndex().
    Alternatively I approached it via Javascript, but it occurred to me that I don't know the id of the field on the row where the commandlink is clicked.Make use of the 'this' reference and pass the commandlink element itself as argument to the JS function.
    onclick="foo(this)"
    function foo(element) {
        var id = element.id;
        // You can do substring and/or replace here and then get element by id from document.
    }

  • Dynamic datatable and command link

    I'm having a problem creating CommandLink's automatically. What we have is a tag, which can contain a set of data. We need this on several locations, so we have to create a datatable dynamically. When you press a link, it should be possible to retrieve the ID of the component on that specific row.
    The problem is, we can create the table with the necessary data. When I construct the column with the ID (and the link), it fails.
    Code:
    HtmlCommandLink link = new HtmlCommandLink();
    Application app = FacesContext.getCurrentInstance().getApplication();
    ELContext elContext = FacesContext.getCurrentInstance().getELContext();
    ValueExpression ve = app.getExpressionFactory().createValueExpression(elContext,"${" + TABLE_VAR_NAME + "." + property + "}", Object.class);
    link.setValueExpression("value", ve);
    link.getAttributes().put("rowId", ve.getExpressionString() );
    link.addActionListener(
        new ActionListener(){
         public void processAction(ActionEvent arg0)
              throws AbortProcessingException {
              LOG.info(">>>>>>>>>>>>> Linked pushed !!"  +
              arg0.getComponent().getAttributes().get("rowId"));
    selectColumn.getChildren().add(link);
    datatable.getChildren().add(selectColumn);The rowId is always #{row.code}, instead of the actual data. Is there a way to create a command link dynamically, press it and retrieve the ID of that field? That expression should be evaluated at runtime and added to the datatable, but that doesn't happen apparently.

    I've read your article, but I didn't find anything I could use. Facing a deadline and don't really have time to try out multiple (possible) solutions. The problem is that all the examples I can find point to MethodBinding, but I don't need that. I just need to get the ID of the row that was clicked, nothing more.
    This works fine:
    link.setValueExpression("value", ve);I don't see why the other expression isn't evaluated.
    I can do getParent().getParent() to get a reference to the DataTable, but the datamodel on that object is empty btw.

  • Selecting the particular cell in the datatable

    hi all,
    sorry for such a stupid question.
    i have a datatable component. i can get the rowid of the particular row.
    but how can i identify the particular cell in that row so that i can update its
    value?
    is it possible to update the cell's value in javascript after identifying it?
    thanks in advance.
    enjoyyy,
    java_buff

    Thanks Edward for ur reply...
    But in Inventory In warehouse report they gave the total as in different color.How they done that?????
    Regards,
    Anitha

  • Getting Id of the row in dataTable

    Hello everyone I have a problem.
    I have a dataTable that looks like this:
         <t:dataTable id="books1" rowOnDblClick="setSelectedRow();" value="#{listtest.list}" var="store">
              <h:column>
                   <h:inputHidden id="rowId" value="#{store.id_list}" />               
              </h:column>
              <h:column>
                  <f:facet name="header">
                        <h:outputText  value="#{listtest.label1}"/>
                   </f:facet>
                   <h:outputText value="#{store.string}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText  value="#{listtest.label2}"/>
                   </f:facet>
                   <h:outputText value="#{store.integer}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText  value="#{listtest.label3}"/>
                   </f:facet>
                   <h:outputText value="#{store.numeric}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText value="#{listtest.label4}"/>
                   </f:facet>
                   <h:outputText value="#{store.timestamp}"/>
              </h:column>
         </t:dataTable>And this code prints me some records.
    What I want is when I double click on a row then some action is starting for example delete action. To delete one record from a list i need the id of this one. And my question is: how to obtain an id from selected row using double click?
    Regards
    Tom

    Ok something is work, but i have a problem with passing this id to my manged bean.
    this my jsp page:
         <t:dataTable
              id="books1"
              rowOnClick=""
              rowOnDblClick="setSelectedRow(this,'login:frik');"
              columnClasses=""
              headerClass=""
              rowClasses=""
              styleClass=""
              value="#{listtest.list}"
              var="store"
              rowId="#{store.id_list}">
              <h:column>
                   <h:inputHidden id="rowId" value="#{store.id_list}" />               
              </h:column>
              <h:column>
                  <f:facet name="header">
                        <h:outputText value="#{listtest.label1}"/>
                   </f:facet>
                        <h:outputText value="#{store.string}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText value="#{listtest.label2}"/>
                   </f:facet>
                   <h:outputText value="#{store.integer}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText  value="#{listtest.label3}"/>
                   </f:facet>
                   <h:outputText value="#{store.numeric}"/>
              </h:column>
              <h:column>
                   <f:facet name="header">
                        <h:outputText value="#{listtest.label4}"/>
                   </f:facet>
                   <h:outputText value="#{store.timestamp}"/>
              </h:column>
         </t:dataTable>
         <h:form id="frik">     
    <h:inputText id="selectedRowId" value="#{listtest.row_id}" />     
              <security:token />
              <navigation:build
                   allRow="#{listtest.allRow}"
                   imgName="img/arrow-.gif"
                   maxPage="#{listtest.page}"
                   maxRow="#{listtest.row}"
                   classImg=""
                   classTable="dateTable"
                   classTr="dateTr"
                   classTd="dateTd"
                   classPagesOn="dateSpanOn"
                   classPagesOff="dateSpanOff"
                   classPageWith="dateSpanActiveOff"
                   leftText="#{msg['Navigation.LeftText']}"
                   midText="#{msg['Navigation.MidText']}"
                   rightText="#{msg['Navigation.RightText']}"
                   activePage="#{listtest.activePage}"
              />
         </h:form>and this is the setSelectedRow method (rowOnDblClick event)
    function setSelectedRow(elem,formName) {
         f = document.forms[formName];
         alert(f.elements[0].id);
         f.elements[0].value = elem.id;
         f.action = '/crm/conversion.jspx';
         f.submit();
    }When I double click on the row the value from the hidden filed(id from db) is passed to filed (selectedRowId) in the form below the dataTable. Than i set the action and then submit the page.
    My question is how to obtain an id from my filed in managed been? Becouse when the page is submitted next one will open and there is no interaction with managed bean.
    Regards
    Tom

  • DataTable in Coldfusion (in cfscript)

    Hi i want to add DataTable in Coldfusion script...Like c# code...C# code is following:
                       DataTable productPropertyFilterTable = new DataTable();
                        productPropertyFilterTable.Columns.Add("RowID", typeof(int));
                        productPropertyFilterTable.Columns.Add("PropertyId", typeof(long));
                        productPropertyFilterTable.Columns.Add("PropertyWeight", typeof(string));
                        productPropertyFilterTable.Columns.Add("LowerRange", typeof(float));
                        productPropertyFilterTable.Columns.Add("UpperRange", typeof(float));

    Hi i have another issue...How can i write this c# code in coldfusion(Script).....
    var warnings = new SqlParameter("ProductPropertyFilter", SqlDbType.Structured);
                            warnings.Value = productPropertyFilterTable;
                            warnings.TypeName = @"[dbo].[ProductPropertyFilter]";
                            using (var ctx = new ProductBookEntities())
                                var productFilter = ctx.Database.SqlQuery<ProductFilter>("dbo.FindScore @ProductPropertyFilter",
                                   warnings);
                                dataProducts = productFilter.ToList();
                                if (dataProducts.Count() > range)
                                    dataProducts = dataProducts.OrderByDescending(x => x.Score).Take(range).ToList();
                                ctx.Dispose();

  • How can i use one datatable inside the other?

    Hi all,
    i need help ... i have this page that shows information from a relational table... for example a mapped table "Countries" that has a java.util.Set inside named "Cities" and i would like 2 know how can i do this using jsf...
    The display would be like this:
    Brasil
    Rio de Janeiro
    Sao Paulo
    USA
    New York
    Washington
    New Orleans
    And Goes on... So i guess it would be a dataTable inside the other, right? but i dunno how to do it...
    Thanks for any info. cya

    this is somehow a messy example. But just focus on the var attribute of outer datatable and how value attribute of inner datatable is referencing it.
    <h:dataTable id="table1" value="#{pc_City_state.listofstates.states}" var="varstates" styleClass="dataTable">
                   <h:column id="column1">
                        <f:facet name="header">
                             <h:outputText styleClass="outputText" value="StateName" id="text2"></h:outputText>
                        </f:facet>
                        <h:outputText id="text3" value="#{varstates.stateName}" styleClass="outputText">
                        </h:outputText>
                   </h:column>
                   <h:column id="column3">
    <f:facet name="header">
    </f:facet>
              <h:dataTable id="table2" value="#{varstates.cities}" var="varcities" styleClass="dataTable">
                                       <f:facet name="footer">
                                       </f:facet>
                                       <h:column id="column4">
              <f:facet name="header">
              <h:outputText styleClass="outputText" value="CityName" id="text6"></h:outputText>
              </f:facet>
              <h:outputText id="text7" value="#{varcities.cityName}" styleClass="outputText">
              </h:outputText></h:column>
              </h:dataTable>
    </h:column>
    </h:dataTable>

  • View images in a datatable from byte[]

    I am trying to view images in a datatable where the image is
    a byte[]. This is what I tried... doesn't work.
    <h:dataTable rows="5" value="#{AirportList.airportList}" var="airport" binding="#{AirportList.airportData}">
              <h:column>
                <f:facet name="header">
                  <h:outputText value="airportCode"/>
                </f:facet>
                <h:outputText value="#{airport.airportCode}"/>
              </h:column>
              <h:column>
                <f:facet name="header">
                  <h:outputText value="airportMap"/>
                </f:facet>
                  <h:inputHidden id="ole" value="#{airport.airportMap}"/>
                  <h:outputText value="#{AirportList.myMap}"/>
                 <div>
                 <!--
                      try
                        byte[] pic = (byte[])request.getAttribute("AirportList.myMap");
                        response.setContentType("image/jpeg");
                        OutputStream os = null;
                        os = response.getOutputStream() ;
                       // os.write(pic);
                        os.close();
                        os = null;
                      catch (Exception ex)
                        out.println("Exception: " + ex.getMessage());
                        ex.printStackTrace();
                   -->
                  </div>
              </h:column>
              <h:column>
                <f:facet name="header">
                  <h:outputText value="airportSugBook"/>
                </f:facet>
                <h:outputText value="#{airport.airportSugBook}"/>
              </h:column>
            </h:dataTable>

    my backing code
    public class Airport
      Collection AirportList;
      private UIData AirportData;
      byte[] MyMap;
      public Airport()
      public Collection getAirportList()
        try{
          InitialContext context = new InitialContext();
          AirportLOBLocalHome home =  (AirportLOBLocalHome)context.lookup("java:comp/env/ejb/local/AirportLOBLocal");
          AirportLOBLocal local = home.create();
          AirportList = local.showAirports();
          Iterator it = AirportList.iterator();
          while(it.hasNext())
            ((OtnAirportLobDetailsLocalDTO)it.next()).getAirportMap();
          return AirportList;
        catch(Throwable e)
          e.printStackTrace();
        return null;
      public void setAirportList(Collection AirportList)
        this.AirportList = AirportList;
      public UIData getAirportData()
        return AirportData;
      public void setAirportData(UIData AirportData)
        this.AirportData = AirportData;
      public byte[] getMyMap()
        OtnAirportLobDetailsLocalDTO ap = (OtnAirportLobDetailsLocalDTO)AirportData.getRowData();
        return ap.getAirportMap();
       // return null;
      public void setMyMap(byte[] MyMap)
        this.MyMap = MyMap;
    }

  • I can't view dataTable in JSF

    Hi, anyone who can help me with java server faces, i want to put data from a resultset to dataTable, i made everithing but my table is not visible.
    My code is:
    <?xml version='1.0' encoding='windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
    doctype-system="http://www.w3.org/TR/html4/loose.dtd"
    doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
    <jsp:directive.page contentType="text/html;charset=windows-1252"/>
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1252"/>
    <title>Consultas</title>
    </head>
    <body><h:form binding="#{backing_Consultas.form1}" id="form1">
    <h:commandButton value="commandButton1"
    binding="#{backing_Consultas.commandButton1}"
    id="commandButton1"
    action="#{backing_Consultas.commandButton1_action}"/>
    </p>
    <p>
    <h:dataTable border="1" var="#{backing_Consultas.dataTable1}"
    id="dataTable1">
    <h:column binding="#{backing_Consultas.column1}"/>
    <h:column binding="#{backing_Consultas.column2}"/>
    <h:column binding="#{backing_Consultas.column3}"/>
    <h:column binding="#{backing_Consultas.column4}"/>
    </h:dataTable>
    </h:form></body>
    </html>
    </f:view>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_Consultas-->
    </jsp:root>
    This es a JSPX page.
    Please any idea
    thanks
    alex

    Try to disable the hardware acceleration in the Flash Player.
    See [[Cannot view full screen Flash videos]]
    Flash "Display settings" window:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html

  • Which one faster- With Rowid or PK

    Hi,
    Recently came across the concepts of IOT(Index organised table). It was mentioned that
    You must specify a primary key for an index-organized table, because the primary key uniquely identifies a row. Use the primary key instead of the Rowid for directly
    accessing index-organized rows. "
    This surprised me as till date I was assuming that the fastest way to access the data from a table is by Rowid. Isn't this contadicting then?
    Can the experts clarify more on these conceps related to IOT.
    Rgds,
    Aashish

    what is the diff betn a Normal table with PK on some column and IOT with almost
    the same structure?The difference is whatever is implied by that "almost".
    Look, the purpose of index organized tables is to do away with a nugatory object when a table and and its primary key index - have basically the same structure. The classic example is the code lookup table, where the difference between the table's columns (code, code_descr) and its primary key (code) is a single column (code_descr). Nearly access of that table is going to be an indexed read on code to get the description. That usage makes it a good candidate for being an IOT.
    Mere creation of PK on a column would give the same result.No. An index organized table is similar to creating an index on (code, code_descr) but without the need to maintain two sets of data. Furthermore the IOT allows us to include non-primary key columns without compromising our relational integrity.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • DataTable.Rows.Count property is occasionally wrong

    I have a web service in C#.NET which calls a stored procedure using ADO.NET. The stored procedure is always returning 1 row, which is then loaded into a DataTable. The Rows.Count property of the DataTable is then examined.
    When this web service is called repeatedly with numerous requests, it occasionally returns Rows.Count as 0 when it should be 1. I have debugged and examined it at runtime and found that there is indeed 1 row in the datatable, but that the Rows.Count property
    is 0.
    Is this a known bug?
    I'm using .Net Framework 2.0
    Note: This is an issue that occurs very rarely. My testing shows that it takes about 90 minutes to recreate it when you have 2 concurrent processes sending requests repeatedly at a rate of about 10 requests per second.

    Are you sure that there aren't multiple threads access the DataTable?
    Can you post a repro? 
    David
    David http://blogs.msdn.com/b/dbrowne/

  • Is there a way to add a column after a filled DataTable from SQL with the same rows?

    My problem is that not to add rows like filled by SQLDataAdapter at the same row in DataGridView. How to make that? I showed below the details with my code also a screen shot, which shows the rows differences from the origin one.
    I don't want to add an expression as column behave in my sql script to get what I need with query result. I don't want to obtain that way.
    using (SqlConnection c = new SqlConnection(ConnStrMSSQL))
    c.Open();
    // 2
    // Create new DataAdapter
    using (SqlDataAdapter a = new SqlDataAdapter("SELECT SIPNO, SERINO, TARIH FROM SNOHAREKETLER WHERE Cast(TARIH as DATE) BETWEEN '2015/03/20' AND '2015/03/20' AND (TEZNO = 'T23' OR TEZNO = 'T31') AND CIKTI is null", c))
    // 3
    // Use DataAdapter to fill DataTable
    DataTable t = new DataTable();
    a.Fill(t);
    t.Columns.Add("MyColumn", typeof(string));
    DataRow workRow;
    int iGetCount = t.Rows.Count;
    for (int i = 0; i <= iGetCount - 1; i++)
    workRow = t.NewRow();
    workRow["MyColumn"] = i;
    t.Rows.Add(workRow);
    dataGridView1.DataSource = t;

    The extra column isn't applied to only certain rows.  The columns of a table identify what data each row will contain.  Hence adding a column to the table automatically adds them to the rows.  What you're seeing is that all the initial rows
    aren't being assigned a value so they retain their default value of null.  Later you enumerate the rows of the existing table and call AddRow which adds new rows.  This isn't adding columns, but rows.
    To generate values for the existing rows you should ideally simply pass the data back from the database.  DT computed columns can be difficult to set up as it is limited to what it can do.  If you want to use a computed column on the Datatable
    itself then define the column as a computed column and every row will calculate its own value.
    DataTable data = GetData();
    //Add elapsed time column
    var col = new DataColumn("ElapsedTime", typeof(TimeSpan), "expr");
    data.Columns.Add(col);
    dataGridView1.DataSource = data;
    The issue you will run into however is that calculating a diff on DateTime doesn't work in a computed column as the expression doesn't support the necessary functions.  You can google for how people solved this if you are interested in alternatives. 
    Most people just tend to add the column and then hook into the various change events to update the value as needed.

  • How can I display one of two DataTables based on criteria

    I have two DataTables. One DataTable should be displayed or the other DataTable should be displayed in the same JSP based on some criteria. I wish I could put an if statement in the JSP page but how else can I do this? Is there a JSF tag that is like an if statement?

    Hi
    Try to use rendered attribute.
    Create boolean variable in your bean ie private boolean showTab1And in jsp type
    <h:dataTable id="tab1" value="..." var="..."  rendered="#{myBean.showTab1}">
    </h:dataTable>
    <h:dataTable id="tab2" value="..." var="..."  rendered="#{!myBean.showTab1}">
    </h:dataTable>if showTab1 is true, first dataTable shows, otherwise second dataTable is shown.
    Hope it helps
    Martin
    ps. You can combine value of rendered :
    rendered="#{myBean.boolVar1 && myBean.boolVar2 && !myBean.boolvar3}"

  • DateField not getting copy in the matrix using Datasource & Datatable

    Hello All,
    I have tried to copy data From Purchase Order Tables to my own created User Defined Form matrix columns using DBDatasource & Datatables ,Instead of Document Date all other data are getting copied but that document date field is not
    getting the data plus it is not showing any error message as such.
    Following is the code which i have written :-
    =====================================
    oPurchase_Amend.DataSources.DataTables.Add("oMatrixDT" )
    oPurchase_Amend.DataSources.DataTables.Item("oMatrixDT" ).Clear()
    Dim sSQL As String = "SELECT T1.[ItemCode], T1.[Dscription], T1.[Quantity], T1.[Price],(Select InvntryUoM From OITM Where ItemCode=T1.ItemCode) as 'UoM',T1.LineNum,T0.DocNum  as 'FrmDate' FROM OPOR T0  INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocNum] ='1' and T0.CardCode='C0001'
    oPurchase_Amend.DataSources.DataTables.Item("oMatrixDT" ).ExecuteQuery(sSQL)
    oMatrix = oPurchase_Amend.Items.Item("mtx_0").Specific
    oMatrix.Clear()
    Dim oDBDataSource As SAPbouiCOM.DBDataSource = oPurchase_Amend.DataSources.DBDataSources.Item("@OSL_POAMD")
    Dim oDataTable As SAPbouiCOM.DataTable = oPurchase_Amend.DataSources.DataTables.Item("oMatrixDT" )
    oDBDataSource.Clear()
    For row As Integer = 0 To oDataTable.Rows.Count - 1
    Dim offset As Integer = oDBDataSource.Size
    oDBDataSource.InsertRecord(row)
    oDBDataSource.SetValue("U_ItemCode", offset, oDataTable.GetValue("ItemCode", row).ToString())
    oDBDataSource.SetValue("U_ItemName", offset, oDataTable.GetValue("Dscription", row).ToString())
    oDBDataSource.SetValue("U_UoM", offset, oDataTable.GetValue("UoM", row).ToString())
    oDBDataSource.SetValue("U_OldQty", offset, oDataTable.GetValue("Quantity", row).ToString())
    oDBDataSource.SetValue("U_OldRate", offset, oDataTable.GetValue("Price", row).ToString())
    > Line For Copying Document Date Data to the matrix datasource
    oDBDataSource.SetValue("U_OldDate", offset, oDataTable.GetValue("FrmDate", row))
    oDBDataSource.SetValue("U_LineId", offset, oDataTable.GetValue("LineNum", row))
      Next
    '--- Rebinding the datasource to the matrix columns -
    oMatrix.Columns.Item("col_0").DataBind.SetBound(True, "@OSL_POAMD", "U_ItemCode")
    oMatrix.Columns.Item("col_1").DataBind.SetBound(True, "@OSL_POAMD", "U_ItemName")
    oMatrix.Columns.Item("col_3").DataBind.SetBound(True, "@OSL_POAMD", "U_OldQty")
    oMatrix.Columns.Item("col_5").DataBind.SetBound(True, "@OSL_POAMD", "U_OldRate")
    oMatrix.Columns.Item("col_7").DataBind.SetBound(True, "@OSL_POAMD", "U_OldDate")
    oMatrix.Columns.Item("col_9").DataBind.SetBound(True, "@OSL_POAMD", "U_LineId")
    oMatrix.LoadFromDataSource()
    But i am not able to get the document date in the column of the matrix .
    Please suggest what changes i have to meke in this code to get the desired output.
    Thanks & Regards,
    Amit
    Edited by: AmitSharma_061985 on Dec 17, 2009 12:24 PM

    Hi Michael,
    FrmDate is the Document date of the purchase order which i am fetching through sql query and trying to copy that in the matrix
    through datasource .
    Edited by: AmitSharma_061985 on Dec 18, 2009 7:07 AM

Maybe you are looking for

  • How do you populate a page item in apex with a value read from excel

    Dear All I am working on application where I am uploading a csv file in oracle apex. I then need to access a value in Cell B2 of the csv file and populate a page item called :P2100_AUTHORISATION_ID with this value. Many of the examples I have found u

  • PowerBook G4 wont read ex, HD, Ipod, Printer, Shufflel - ahhhh, help?

    PowerBook G4 wont read external HD, Ipod, Printer, Shufflel - ahhhh, help? Im not the whizziest on computers, other than lve tried a few things and nothing seems to work - lm open to any suggestions. Each external device makes sounds, which sounds li

  • Visual Studio 2008 Crystal Report 10.5 merge modules download

    Hi All, I'm struggling with this problem about 2 weeks and still cannot find the resolution. I was developed a .Net application with visual studio 2008 and using crystal report to generate report. It is working fine in my local machine. However, afte

  • Can't import .jpg photos

    I received a group of .jpg photos both by e-mail and on a CD and some of them will not import into iPhoto 09, I get the error message "the file is in an unrecognized format". Some of them import normally. I can open the bad ones in Photoshop and resa

  • IDOC filename change

    Dear All, We have configuration for Idoc in our SAP 4.7 as , - While creating billing document - VF01 (for a specified output type), Idoc is     created and saves in application server path. - For naming convention of Idoc, We have used FM - "EDI_PAT