How to hide column of DataGrid

I am making a web part in which I am using System.Web.UI.WebControls.DataGrid control.
It's AutoGenerateColumns property is set to TRUE.
I am trying to hide a column at run time. I have written the following code on this controls ItemCreated event but it only works if I e.Item.Cells[0] and it doesn't work for any other value for e.g. e.Item.Cells[1] and e.Item.Cells[6].
There are 9 columns in my DataGrid control.
Code
protected void grd1_ItemCreated(object sender, DataGridItemEventArgs e)
{ e.Item.Cells[0].Visible = false; //works fine
e.Item.Cells[1].Visible = false; //gives error e.Item.Cells[2].Visible = false; //gives error
Error
Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
How to hide a particular column?

Hi Frank,
You can try something similar to the below in 'RowCreated' event Instead
protected void gridView_RowCreated(object sender, GridViewRowEventArgs e)
e.Row.Cells[1].visible =false;
OR I would say hiding column is not something that is to be done at row level, so you can hide columns outside any of the grid view event after binding.
e.g.
gridview1.columns[1].visible=false;
I am using DataGrid control in which there is no RowCreated event.
I have tried second approach but it also doesn't work.

Similar Messages

  • How to Hide Column

    Hello,
    How can I hide columns within an AdvancedTable programmatically? Ex. All columns shall be shown if the value of my dept is "Dept1" while only Column1 to 2 shall be shown if my dept is "Dept2"? Pls advise. thanks

    As Kumar rightly pointed out, you need to refer the Dev guide for this. Refer the section on Partial Page Rendering.
    To summarize you would have the Rendered Property on the columns like this
    ${oa.<VoName>.<VOAttributeName>}
    Based on the conditions you would set the attribute value(which is boolean) to true or false and accordingly either the column with show or hide. The VOName is the name of the Partial View Object you create for the purpose. Do let us know if you have difficulty in understanding PPR.
    Regards
    Sumit

  • How to hide column in BEx Analyzer

    Hi gurus
    In my report I have to show 5 columns depending on a condition.
    Is it feasible?
    Regards

    Hi,
        You can use VBA Macro to execute Code to hide the columns based on the condition.
    This is in 3.5
    Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
               'Check you condition
               If <condition> Then
                       'This will hide Column 3 on Sheet1 where the Query is.
                       ThisWorkbook.Sheets("Sheet1").Columns(3).Hidden = True
               End If              
    End Sub

  • How to hide columns in the output table in webdynpro based on input

    Hi Experts,
       I have 2 inputs and 1 input is optional.If both inputs are given proper table output is displayed,but if only 1 input is given a column is empty in the output table  so i want to hide this column dynamically at runtime based on my inputs.And i want to hide some empty rows also at runtime based on inputs.
    Can anyone help me out to solve this.
    Thanks in advance.
    Regards,
    Anita.

    Hi Anitha,
    What i understood from your question is,you want to control the table from your inputs.I have a one question for you what do you want to show defaultly i.e when you run the application what you want to show,either no table or table with some values.
    Any how i am giving solution in this way.
    If both inputs are given proper table output is displayed
    Write your below logic in the WDDOMODIFYVIEW )
    Here i am assuming that you already have a table element in the view.
    Get the values entered in the input fields and compare those 2 values ,if the condition is satisfied then bind the values which you want to show in the table to the context node.
    but if only 1 input is given a column is empty in the output table so i want to hide this column dynamically at runtime based on my inputs
    You are telling that you know the empty column.If so get the view element reference and use the REMOVE_COLUMN to remove the column.
    data:lr_table type ref to cl_wd_table,
           lr_column type ref to L_WD_TABLE_COLUMN.
    lr_table ?= view->get_element( 'TABLE1' ).
    CALL METHOD LR_TABLE->REMOVE_COLUMN
        EXPORTING
          ID          = 'TABLE1_color'
         INDEX      =
        RECEIVING
          THE_COLUMN = lr_column.
    i want to hide some empty rows also at runtime based on inputs.
    Removing the rows is very simple.if you know the key fields data of internal table from your input fields then do in this way.
    delete itab from wa where key1= "12" and key2="abd".
    Now bind the internal table to context node.
    LO_ND_hcm->BIND_TABLE(
          NEW_ITEMS            = it_final
          SET_INITIAL_ELEMENTS = ABAP_TRUE ).

  • How to hide columns that are getting added dynamically to UI Element 'Table

    In SRM 7.0 while displaying a RFx, click on "responses and awards" button.
    In the response comparision tab once the user selects response number and clicks on "compare all responses".
    Item details table is displayed with fields item number,internal number,item description,........,Price etc.
    Requirement is  to hide the price column from the table.
    The UI element type is 'Table'.
    But the catch is there is no column price visible at layout design level.
    This field is getting added dynamically at run time.
    When i right click and see the 'more field help' at the front end i get the field id as 'GRP_1_COL_3_TXTV'.
    lo_table ?= view->get_element( id = 'ITEMS_TABLE' ).
    lo_column = lo_table->get_column( id = 'GRP_1_COL_3_TXTV').
    ASSERT lo_column IS NOT INITIAL.
    lo_column->set_visible( EXPORTING value = '01' ).
    I had written the above code in the pre-exit of WDDOMODIFYVIEW.
    But i am getting dump as assertion failed.it says no column by name 'GRP_1_COL_3_TXTV'.
    Please help me inhow to hide fields or buttons getting generated dynmically.
    Regards,
    Venkat Raghavan.

    Hi Anitha,
    What i understood from your question is,you want to control the table from your inputs.I have a one question for you what do you want to show defaultly i.e when you run the application what you want to show,either no table or table with some values.
    Any how i am giving solution in this way.
    If both inputs are given proper table output is displayed
    Write your below logic in the WDDOMODIFYVIEW )
    Here i am assuming that you already have a table element in the view.
    Get the values entered in the input fields and compare those 2 values ,if the condition is satisfied then bind the values which you want to show in the table to the context node.
    but if only 1 input is given a column is empty in the output table so i want to hide this column dynamically at runtime based on my inputs
    You are telling that you know the empty column.If so get the view element reference and use the REMOVE_COLUMN to remove the column.
    data:lr_table type ref to cl_wd_table,
           lr_column type ref to L_WD_TABLE_COLUMN.
    lr_table ?= view->get_element( 'TABLE1' ).
    CALL METHOD LR_TABLE->REMOVE_COLUMN
        EXPORTING
          ID          = 'TABLE1_color'
         INDEX      =
        RECEIVING
          THE_COLUMN = lr_column.
    i want to hide some empty rows also at runtime based on inputs.
    Removing the rows is very simple.if you know the key fields data of internal table from your input fields then do in this way.
    delete itab from wa where key1= "12" and key2="abd".
    Now bind the internal table to context node.
    LO_ND_hcm->BIND_TABLE(
          NEW_ITEMS            = it_final
          SET_INITIAL_ELEMENTS = ABAP_TRUE ).

  • How to make XML element used in RTF PRIVATE/PUBLIC ? I know how to hide columns in RTF, but dont know how to generate the xml in below way. Please help.

    Hi
    I am following below link to hide/show my columns dynamically. See "Column Formatting"
    http://docs.oracle.com/cd/E12844_01/doc/bip.1013/e12187.pdf
    As per doc, element can be made private/public.
    <items type="PUBLIC">
    <item>
      <name>Plasma TV</name>
      <quantity>10</quantity>
      <price>4000</price>
    </item>
    <item>
    And same can be used to hide the column using condition
    <?if@column:/items/@type="PUBLIC"?>
    MY QUESTION IS HOW TO DO THIS IN MY XML BELOW?
    Below is part of my XML code which I am using in Data Definition for RTF.
    <group name="GH3" source="QH3">
    <element name="COLUMN_HEAD3" value="COLUMN_NAME" />
    </group>
    <group name="GH4" source="QH4">
    <element name="COLUMN_HEAD4" value="COLUMN_NAME" />
    </group>
    I am getting output like this.
    <LIST_GH3>
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4>
    <GH4>
    <COLUMN_HEAD4>XYZ</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    In order to use logic as per oracle document I want output like this.
    <LIST_GH3 type="PUBLIC">
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4 type="PRIVATE">
    <GH4>
    <COLUMN_HEAD4>BLANK</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    What changes I need to make in my XML code to get the runtime output as above? Please help. Where do i need to make changes in the above xml? Group name? Element name?
    I am planning to use below condition in RTF template to hide the column,  but dont know how to set the type of column as PRIVATE/PUBLIC in the XML output used to populate data in the RTF at runtime.
    <?if@column:/BTSPIEXP/LIST_GH3/@type=”PUBLIC”?>COLUMN_HEAD3<?end if?>
    Regards,
    Swapnil K.

    Hi,
    Issue has been resolved. I used the value of the element to determine to display it or not.
    Regards,
    Swapnil K.

  • How create grouped column in DataGrid ?

    Hi all,
         I can create grouped column in AdvancedDataGrid. So in DataGrid, how I create grouped column ?
    Thanks.

    I have a problem that no anyone can help me to now. Sometime, I think that it's bug of ADG.
    My goal same as from http://blogs.adobe.com/aharui/BlinkWhenChanged/dg.swf . But if I use ADG and with a scroll ! And when scroll up or down background color change not right.
    It's a big problem ! Yep, when I use ADG, I can create group columns but ADG, I can't !
    Is there any ways for me?

  • How to hide columns in each page of SSRS report for grouped tablix

    Hello all,
    I have a requirement like when SSRS report (used row grouping)is exported to EXCEL
    1)  Each report page should be exported to a separate excel sheet
    2) Each sheet will have different columns (that is some columns will hide in sheet2, sheet3...)
    3) Eg: If a country report is there with details like country name, country code, currency code. Now each country details should export to separate excel sheet and sheet 1 should show Country Name and Country code; Sheet2 should show: Country Code, Currency
    Code; Sheet3 should show: Country Name, Country Code, Currency Code.
    I am done with point#1 above: Each report page should be exported to a separate excel sheet. Can some one help on point#2:Each sheet will have different columns (that is some columns will hide in sheet2, sheet3...)
    Thanks,
    Paandey : Dont forget to mark it as Answered if found useful

    Hi paandey,
    According to your description, there are three columns named country name, country code, currency code in the report. When export the report to excel, you want to show Country Name and Country code in sheet1, Country Code and Currency Code in sheet2, and
    show all of the three columns in sheet3.
    In Reporting Services, we couldn’t achieve your goal by setting visibility of columns in one tablix. As a workaround, we can use three tablix in the report, then add page break to the tablix. For detail information, please refer to the following steps:
     1. Since you have created a tablix with three column, copy and paste it to the report twice.
     2. Right-click column handle of Currency code in tablix1, click Column Visibility.
     3. Check Show or hide based on an expression, click (fx) button, then type the expression:
    =(Globals!RenderFormat.Name = “EXCELOPENXML”)
     4. Right-click column handle of Country name in tablix2, set its visibility like step3 above.
     5. Select and right-click tablix2, click Tablix Properties.
     6. In General pane, in Page Break Options section, check Add a page break before check box.
     7. Click Visibility in left pane, check Show or hide based on an expression, click (fx) button, then type the expression:
    =(Globals!RenderFormat.Name <> “EXCELOPENXML”)
     8. Select and right-click tablix3, add page break to it like step6 above.
     9. Set its visibility like step7 above.
    The following screenshot is for your reference:
    For more information, please refer to the following document:
    http://blogs.msdn.com/b/robertbruckner/archive/2010/05/16/report-design-naming-excel-worksheets.aspx
    If you have any more questions, please feel free to ask.
    Best Regards,
    Wendy Fu

  • How to hide columns in ALV? (via cl_salv_table)

    Dear forumers,
    Is there a way for me to hide a few columns (or data fields) from being displayed in the ALV table, using the cl_salv_table method?
    FORM display_data_alv .
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = o_table
            CHANGING
              t_table      = i_ro_assets.
        CATCH cx_salv_msg.
      ENDTRY.
      o_functions = o_table->get_functions( ).
      o_functions->set_all( abap_true ).
      o_columns = o_table->get_columns( ).
      o_columns->set_optimize( abap_true ).
      PERFORM set_columns.
      o_events = o_table->get_event( ).
      CREATE OBJECT o_handle_events.
      SET HANDLER o_handle_events->on_double_click FOR o_events.
      o_table->display( ).
    ENDFORM.                    " DISPLAY_DATA_ALV
    FORM set_columns .
      TRY.
          o_column ?= o_columns->get_column( 'BUKRS' ).
          o_column->set_long_text( text-008 ).
        CATCH cx_salv_not_found.
      ENDTRY.
      TRY.
          o_column ?= o_columns->get_column( 'ANLN1' ).
          o_column->set_long_text( text-009 ).
        CATCH cx_salv_not_found.
      ENDTRY.
    ENDFORM.                    " SET_COLUMNS
    I have also tried to exclude some columns from the subroutine SET_COLUMNS, but they are still showing in the resulting ALV table. What can I do here next?
    Appreciate any help here.
    Thanks very much.

    You can use the method SET_COLUMN_TECHNICAL of the class CL_SALV_COLUMN  to hide the Column.
    data:
      ir_columns type ref to cl_salv_columns_table,
      lr_column type ref to cl_salv_column.
      try.
          lr_column = ir_columns->get_column( 'MANDT' ).
          lr_column->set_technical( if_salv_c_bool_sap=>true ).
        catch cx_salv_not_found.                            "#EC NO_HANDLER
      endtry.
    Check the report SALV_DEMO_TABLE_COLUMNS to know more about the Column processing in SALV model.
    Regards,
    Naimesh Patel

  • How to hide column link URL on status bar?

    Apex 4.1
    I have IR wit one column link target to URL, and it uses
    javascript:my_function(#COLUMN_VALUE#)as URL, that is, calls some function and passes the value of that column to the function;
    everything works fine;
    but when I place a cursor over the link, bottom line of IE9 browser (is it called a 'status bar'?) clearly shows:
    'javascript:my_function(<actual value>)'
    Is there any way to prevent it from showing function name and parameter value?
    I tried
    onmouseover="window.status='';"but it does not work

    Don't name the function in your link and hide the code in a dynamic action. See this example:
    http://apex.oracle.com/pls/apex/f?p=31517:296
    and the empno column which is a link. Explanation further down.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • How to hide columns in SSRS Reports

    I have allocation list which has various columns and weekly allocation text columns like Week1Allocation,Week2Allocation,Week3Allocation ……Week51Allocation.
    I generating a report in which I am showing resource and there allocation in below form
    Resource Name Week1Allocation,Week2Allocation,Week3Allocation ……Week51Allocation
    Xyz                                      
    40                         
    40                         
    43                                        
    11
    While creating report I drag and drop Week Columns in value field and resource name in Row field.
    My requirement is to show Week column starting from current week and next 3 week, How can I achieve this in SRRS or What should I do to get the reports in desired form, What could be the best possible
     design (List design ) for scenario. Please suggest.

    Hi Alok,
    In your scenario, if we want to show Week column starting from current week to next 3 week, we should use expressions to control the 51 columns visibility. This is not a sensible method.
    Generally, we always use one column contains Week1Allocation, Week2Allocation, Week3Allocation ……Week51Allocation values, other than create 51 columns. So I suggest we can modify the dataset to use one column (Week) contains those weeks and other column
    (Allocation) contains the corresponding values, then we can drop Week column under Resource_name in Row groups and drop Allocation column in Values field. Then use the expression below to control the Allocation column visibility:
    =iif(Fields!Week.Value=datepart("ww",today) or Fields!Week.Value =(datepart("ww",today)+1) or Fields!Week.Value =(datepart("ww",today)+2),false,true)
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How Auto Fit column in DataGrid

    Is it possible to set autofit in DataGrid column ?
    Without auto fit the users must resize the table every
    time.

    Please Check this example
    http://www.flex4ex.com/?p=24

  • How to Hide Columns Based on Condition

    Hi All,
    i have an SSRS Report with below four columns.
    Product_Name , Year , Credit_Amount , Debt_Amount
    I want to hide the Credit_Amount Column if that column all values are Zero.
    In the same way needs to hide Debt_Amount Column if that column all values are Zero.
    Thanks in advance.
    bala krishna

    Step 1- Right click on your required Column here in below example: I wanted to hide
    Name column
    and select Column Visibility
    Step 2- From the
     Column Visibility window , select Show or hide based on an expression and
    then click on fx button as shown in below screenshot
    Step 3- Write Your expression in expression windows as below
    =IIF(Fields!Credit_Amount.Value = 0, True, False)
    Repeat step 1 to Step 3  for Debt_Amount column .
    Sandip Pani http://SQLCommitted.com

  • How to hide one column in PIVOT(in Union )

    Hi experts
    I have one problem regarding my Pivot report.
    I have to calculate MTD an YTD in my single report so i have calculated MTD in one criteria (UNION) YTD in second criteria.
    In my MTD i have to show 4 column: A B C D
    and in YTD I have to show only 3 column : A B C
    So how to hide column D in YTD.
    Thanks in advance
    Regards
    Frnds

    Hi John
    I have done :
    1. when i do cast as null to my D column in second report. I am getting error
    (Union for non compatible)
    2. so i done the cast in first report also..
    3. Done the union all
    4.and done the HIDE for column D in Result Column..
    But still i am seeing it in my report in YTD...
    So please help me its very urgent for me..

  • Expression to Hide Column

    Hello everyone...I am using web application.Can anybody tell me how to hide column if data is not present in it in RDLC table using nchar type of data.I have used expression for it but its not working As column is hided but  if I insert some
    value in that column then it should display value but it is not displaying,it hides column.

    Hi Sayali,
    Is the issue same as raised in below thread? Try out the fix provided by Wendy Fu and also other expressions provided in there.
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/76bba7ad-e6a0-4b7b-b17d-885494439446/column-visibility-issue-in-ssrs2012?forum=sqlreportingservices
    -Vaibhav Chaudhari

Maybe you are looking for