Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Checkbox in Datagrid Column
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Checkbox in Datagrid Column

 Post Reply Post Reply Page  12>
Author
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Topic: Checkbox in Datagrid Column
    Posted: 11 January 2005 at 10:31am
I have a datagrid that lists results of a user-run search. I would like to add checkboxes in each column where the user can check/uncheck the checkbox in each column to hide columns he/she doesn't wish to see.
 
The problem is that I am having trouble accessing checkboxes in the columns as column does not appear to contain "item".  I have read endless tutorials and discussion forums about checkboxes in datagrids, but it seems that everyone else is using them to highlight rows in the grid (a la Hotmail).
 
I have also had problems referencing my checkboxes.... "not set to an instance of an object". I think I have resolved that issue for the most part, but the problem with putting checkboxes in the columns and then referencing them from there still remains.
 
Is there something I am missing? I can't believe that I am the only person to want to allow users to dynamically hide/unhide columns in a datagrid list. 
 
Any advice or help would be greatly appreciated. Thank you. 
 
 
 


Edited by sabrin514 - 11 January 2005 at 10:33am
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 10:33am
Oh I forgot to mention that once columns are hidden, the user can again display them all by clicking a "show all" button that would set the visible column of each column to true again.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 11:08am
That is just some pseudo code I have not tested, but should give you the idea:

<asp:datagrid id="DataGrid1" runat="server">
the in each column put something like
<FooterTemplate>
    <asp:Checkbox id="chkHide[N]" runat="server" CommandName="Select"></asp:TextBox>
</FooterTemplate>
replace N for each column with a number
 
Then in your Codebehind:
 
Private Sub DataGrid1_ItemCommand(.......) Handles  DataGrid1.ItemCommand
 If e.CommandName = "Select" Then
    Dim c1 As CheckBox = e.Item.FindControl("chkHideCol1")
    'Repeat the above for each column
   
    If c1.Checked THEN
        DataGrid1.Columns(1).Visible = False        
    End IF
 End IF
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 11:09am
</asp:TextBox> is checkbox of course, sorry
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 11:22am
Thanks. I'll give it a try. Would it make any difference if I substituted  HTML checkboxes (using runat="server") for the asp checkboxes? Thanks again.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 11:23am
Yes, a html checkbox will be of the type HtmlGenericControl and an asp one if type of Checkbox
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 2:58pm
Thanks for your response. I am still having some problems though.
 
I would prefer to not use the footer as the datagrid result lists can be quite large and I do not want the user to have to reach the end to hide/unhide columns. I stuck the asp checkbox in the header instead and it seems to be okay, except...
 
CommandName is apparently not part of the asp checkbox. Do I need to add attributes? If so, how do I do that? I realize that any added attributes probably would need to be taken care of on or before the page load event.
 
Also, the asp checkbox does have a built in oncheckedchanged event, however, I have having trouble utilizing this because I am having trouble referencing the checkboxes using findcontrol(checkbox name) because I cannot pass in the item I need to or it is not part of the params I can pass in with the oncheckedChanged event.
 
If you have any advice, I'd be grateful. I feel like I am banging my head against a wall with this. The final solution will probably end up being far more simple than I am imaging it to be at this point.
 
 


Edited by sabrin514 - 11 January 2005 at 3:09pm
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 11 January 2005 at 3:16pm
Oh I forgot to mention this and I'm not sure it makes any difference, but I also have asp linkbuttons in the column headers so that the user can sort the columns in asc or desc order. That seems to work fine since link buttons have a commandName and commandargument attribute built in.  Checkboxes don't, and there does not seem to be any Item property or attribute for column headers.... only the "items" in the grid; therefore I am having a heck of a time referencing them. Sorry if I am misusing the terminology.

Edited by sabrin514 - 11 January 2005 at 3:22pm
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.