I am trying to hide a column in a gridview but need access to the data in these fields.
I have a gridview with columns that I want to hide but still need to access this data at the row level. What is the best way to achieve this? (Using Visual Studio 2013)
OK - I posted the question then posted the answer. I tried to find the answer and discovered the question was asked a
lot, and many had 30 or more posts on the question. Since I spent way to much time looking at forums/discussions and figuring it out, I thought that I should repost the question then answer it. Hopefully if someone stumbles on it it might save
them some time.
I tried setting column widths, setting columns to visible=false before a bind (and after a bind), CCS, TemplateFields etc etc. All had problems either in the display, paging or retrieving the data in the gridview events (RowCommand & RowDataBound).
I am not saying the others won't work but this is the way I got it to work. As with most coding issues once you have the answer it looks pretty simple.
First of all forget about trying to hide columns - Use DataKeyNames in the GridView.
Here is what I am trying to do - Based on the data in the "hidden columns" in the row, I want to manipulate how the Grid will appear. (Buttons will or will not appear)
SQL:
Select [FruitID], [StuffDesc], [ActionAFlag], [ActionBFlag] from [Friut] ORDER BY [StuffDesc]
ASPX:
<asp:gridview id="Gridview1" AllowPaging="True" runat="server"
autogeneratecolumns="False"
onrowdatabound="GridView1_RowDataBound"
onrowcommand="GridView1_RowCommand"
Datakeynames="FruitID, ActionAFlag, ActionBFlag">
<Columns>
<asp:BoundField DataField="StuffDesc" Headertext="Made up Stuff" />
<asp:ButtonField ButtonType="Button" CommandName="FireA" Text="Action A" />
<asp:ButtonField ButtonType="Button" CommandName="FireB" Text="Action B" />
</Columns>
</asp:gridview>
ASPX.VB
RowDataBound fires before each row is rendered to the Gridview. The data in ActionAFlag and ActionBFlag will determine which buttons show. If the data in field ActionAFlag is 1 then "Action A" button shows; if field ActionBFlag
is 1 then "Action B" shows. First it checks to see that you are dealing with a DataRow, (not Headers or Footers). Note variable "rowcounter" [I could not figure out how to get the row number from GridviewrowEventsArgs so I fudged it by
using a global variable and setting it to 0. Each time the page is rendered the Rowcount is automatically set to 0]
Protected Sub GridView1_RowDataBound(ByVal Sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim AShow As String = Gridview1.DataKeys(rowcounter).Values("ActionAFlag").ToString
Dim BShow As String = Gridview1.DataKeys(rowcounter).Values("ActionBFlag").ToString
If AShow <> "1" Then
e.Row.Cells(1).Text = " "
' -- Blank Action A Button ---
End If
If BShow <> "1" Then
e.Row.Cells(2).Text = " "
' -- Blank Action B Button ---
End If
rowcounter = rowcounter + 1
End If
RowCommand fires on page changes or if a button on a row is clicked. I want to capture the FruitID and execute the appropriate button action. Here I can get the Row Index
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "FireA" Or e.CommandName = "FireB" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim FruitID As String = Gridview1.DataKeys(index).Values("FruitID").ToString
If e.CommandName = "FireA" Then
MsgBox(" In FireA / FruitID = " + FruitID)
Else
MsgBox(" In FireB /FruitID = " + FruitID)
End If
End If
End Sub
Similar Messages
-
Hide a column in one view, but show in other
Hi all.
I need to hide a column on "Table" view, but column needs to show up on "Pivot table".
I know we can hide it on pivot ( exclude It ) and show on table, but I want to know if reverse is possible.
This is needed because I am doing a view selector for writeback. And I dont want to display all the columns on writeback table view. But it needs to be there on Pivot table.
Please let me know if it is possible.
Thanks.
VinayYes we can do that.
Check on the "Hide" in the column format tab of the column that you need to display in the table lay out.
Now dupliate the same view and in the pivot table column intially you will not see the column displayed.
Now in the properties check on "hidden" in the "format headings" and you wont see it still and now uncheck the"hidden" and you shoud be able to see the column displayed in the pivot view
In this way you will have the column hidden in the table view and displayed in the pivot table.
Hope it helps
Prash -
How do I find which photo iPhoto is telling me I have a problem with?
I'm trying to buy a book I've formatted, but in place of the filename, it just calls it "(null)".
All of the photos I'm using have names.That same one others seem to have gotten: "Unable to Assemble Book -- There is a problem with the photo with the filename “(null).” The full resolution version of this photo either cannot be located or is corrupt. Please replace this photo or delete it from your book"
I've tried restarting iPhoto with the option and command keys pressed, and asking it to repair permissions, but still have the same message... -
I am trying to add a bookmark in safari ios7, but when I tap the box with the upward arrow no options appear anywhere on screen to add a bookmark. In fact the screen freezes and I have to close safari to be able to unfreeze it. What is wrong, can anyone please help me? Thanks
please ignore this question, I added the ios7.0.2 patch and the bookmarks can now be added through the action icon. cheers
-
Please help me. My YouTube app will not work. Every time I open it says 'cannot connect to youtube'. I have searched for help and tried resetting my settings and rebooting my ipad2 but nothing has solved the issue.
Yes, I am connected to the Internet through my wifi. Everything is working fine with the e eption of youtube. I have reset all Internet settings and have tried synching to iTunes followed by rebooting. This is all the advice I have found although none of it has been helpful.
Has anyone else encountered this problem? -
I tried to uninstall my really old iTune version but it came up the error code: 2324. I then copy the data of the new version of iTune from my friend's disk C and paste them onto my disk C. However, it seems to work but appear another error code: -42404. I don't know what's going on. Can someone help me please? I just got the latest iPod nano and it ***** that I can't synchronize my music! :/
Cheers!Zac henderson wrote:
...Couldnt restore ipod, error code (9) " ...
Try here > Configure security software -
Trying to upgrade my iTunes to 10.5 but I keep getting the message "the URL could not be opened". What do I do?
Use this: http://appldnld.apple.com/iTunes10/041-2598.20111011.9Cp3o/iTunesSetup.exe
-
I keep trying to add songs to my wish list but when I view the list there's nothing there.
I keep trying to add songs to my wish list but when I view the list there's nothing there.
You click on an item's price to buy it - there used to be a 'buy all' button on the wish list screen, but for some reason that has been removed from the current version of iTunes, so you can only buy items individually by clicking on their prices.
-
Trying to create my courses using Adobe Captivate, but even after saving the files as a pdf it will not upload in Udemy. What can I do?
Yep, you lose all interactivity when publishing to video.
Udemy, Lynda.com, Total Training and other similar models are based on simple "watch the video to learn" type of consumption. The only real interactivity you get is an ability to pause, rewind, fast forward. Basically anything you can do with a video.
Cheers... Rick -
I'm trying to download a free trial of InDesign but when I click the download button, nothing happens...does anyone know why? Thanks.
Hello,
sometimes the "opm.db file" is the culprit. In this case you should delete it.
And if it doesn't work still after that, as much as I regret it and as strange as it may seem I fear it's a challenge for Adobe's Creative Cloud Cleaner Tool.
Sometimes - for whatever reasons - CC doesn't "want" to work. In this case you should CC completely delete and reinstall by help of Adobe Creative Cloud Cleaner Tool. (A try to uninstall by own resources is not enough!)
I quote: ... helps resolve installation problems for Adobe Creative Cloud and Adobe Creative Suite (CS3-CS6) applications. The tool removes installation records for prerelease installations of Creative Cloud or Creative Suite applications. It does not affect existing installations of previous versions of Creative Cloud or Creative Suite applications.
Please use: http://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.html and follow the prescribed sequence of operations
If necessary and for further questions click through http://helpx.adobe.com/contact.html or http://helpx.adobe.com/de/contact.html and if "open" please use chat, I had the best experiences.
Good luck!
Hans-Günter -
I was trying to burn a CD from a playlist but it keeps burning the CD out of order. The shuffle button is not selected. Any ideas?
Could you post your diagnostics for us please?
In iTunes, go "Help > Run Diagnostics". Uncheck the boxes other than DVD/CD tests, as per the following screenshot:
... and click "Next".
When you get through to the final screen:
... click the "Copy to Clipboard" button and paste the diagnostics into a reply here. -
I was trying to update my ipod to iOs 5 but I have forgotten the backup password
I was trying to update my ipod to iOs 5 but I have forgotten the backup password help please?
You need to restore your iPod to factory defaults/new iPod. That is the only choise.
Warning: If you encrypt an iPhone backup in iTunes and then forget your password, you will not be able to restore from backup and your data will be unrecoverable. If you forget the password, you can continue to back up and use the device, however you will not be able to restore the encrypted backup to any device without the password. You do not need to enter the password for your backup each time you back up or sync.
If you cannot remember the password and want to start again, you must perform a full software restore and when iTunes prompts you to select the backup from which to restore, choose set up as a new device.
Above from:
http://support.apple.com/kb/HT4946 -
I have a numbers spreadsheet for tracking company data. I want to copy the format of the spreadsheet (rows, columns,and formulas) but have all of the data fields be blank for the new year. How do I do that?
click and hold on one cell, then drag to select the range, then release, then type the delete key. Only inlude cells in the range you do not want to keey the contents of the cell. You can remove one-off cells by holding the command key and clicking cells to add or remove as needed.
You can download the Numbers users guide here:
http://support.apple.com/manuals/#productivitysoftware -
I have given my iPad and iPhone to my wife, she has synchronized with her Apple ID but it keeps going back to my Apple ID when she tries to purchase something in iTunes. Do I need to deregister the device and register it in her Apple ID?
What id shows at the bottom of the Featured tabs in the App Store apps on the two devices ? If they still show your account id then try tapping on the id and log out of it and your wife can then try logging in with her account.
Any content that is already on them that was downloaded by your account will remain tied to your account, so only your account will be able to download updates to your apps. -
Tried to purchase Gems in King's Empire but I keep getting the message contact iTune Support to complete transaction.
Do exactly what it told you to do.
Contact itunes support
Maybe you are looking for
-
How to I point to my itunes library with my new computer?
I have recently got a new computer and so I've reinstalled itunes. I backed up all my music from my old machine and have copied it to my new machine. How do I tell my new machine where that folder is? All the music is in folders under C:\iTunes Mu
-
Flash Builder 4.5 Java Heap Space Error
Hello everyone, I've downloaded Flash Builder 4.5 trial a few days ago. Let me first tell that I like the new features a lot and they help to speed up the development process noticably. I thank Adobe for that very much. However I did not notice any p
-
Why is The iTunes Library Extras.itdb file locked?
After my walk this morning I tried to connect up to iTunes to chargemy ipod and update my tunes and got an error message: "The iTunes Library.itdb file is locked, on a locked disc, or you do not have write permission for this file." WHY WHY WHY ???
-
Saving a Mac Word file by printing to PDF not possible anymore
I have a old version of Office v.X for Mac that will no longer allow me to save files by printing them as save to PDF. I think the problem occured when I switched to Mac OS X 10.6.8. Does anyone know what the problem maybe and how I can fix it?
-
Is there any documentation on TSAutoMgr.exe?
I noticed a while back that the TSAutoMgr.exe server is executed whenever you create a TestStand engine. I peeked at the tlb for the server and it looks like you wrote a remotable version of the GIT. Cool. Unfortunately there's no way to discover the