Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
| Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2012, 03:11 AM
Authorized User
Points: 173, Level: 3
Points: 173, Level: 3 Points: 173, Level: 3 Points: 173, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default I have a question about using a checkbox list inside a listview.

I was wondering if this could be implemented:

I have a listview of items and I have a separate database table that contains an item id along with a size.

When a user enters in an item they will be able to select sizes for it from a list of all available sizes. They may choose however many sizes they like for the particular item.

In the listview, when they go into edit mode I would like to populate a checkboxlist with whatever sizes they already have selected and let them change it up and save.

I was thinking that maybe I could get into the on_editing event and query the database with the primary key of the item to get at all the sizes associated with it and then programmatically populate the checkbox with the correct selections.

When they change them in edit mode I could try and into the on_updating event and figure out which checkboxes are selected and then send that to the database in code behind.


Would this approach work or is there a much easier and more elegant solution?

Any help would be appreciated. Imar
 
Old May 19th, 2012, 08:54 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This sounds reasonable to me.

Rather than a ListView with inserting / editing behavior, you could also hand-code a page like this for one specific item. It all depends on the data and how you want your user to interact with it.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
IceThatJaw (May 19th, 2012)
 
Old May 19th, 2012, 12:55 PM
Authorized User
Points: 173, Level: 3
Points: 173, Level: 3 Points: 173, Level: 3 Points: 173, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
This sounds reasonable to me.

Rather than a ListView with inserting / editing behavior, you could also hand-code a page like this for one specific item. It all depends on the data and how you want your user to interact with it.

Cheers,

Imar
I see. The thing is that this is just one option for the item. I will be also implementing the same checkboxlist for colors and they will be able to view and edit a number of other options for the item, as well as deleting it. I guess I could just put in my own edit button that redirects to a new page with the item id that was selected and have them do all the editing there on it's own page. It might be neater that way.

Thanks for the feedback.

Last edited by IceThatJaw; May 19th, 2012 at 12:58 PM..
 
Old May 19th, 2012, 02:02 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I guess I could just put in my own edit button that redirects to a new page with the item id
Exactly. Or even better, use some nice overlay mechanism such as Fancybox and display the new page in an iframe so you never leave the original page.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 19th, 2012, 03:31 PM
Authorized User
Points: 173, Level: 3
Points: 173, Level: 3 Points: 173, Level: 3 Points: 173, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Exactly. Or even better, use some nice overlay mechanism such as Fancybox and display the new page in an iframe so you never leave the original page.

Cheers,

Imar
Oh, nice. That fancybox looks cool.

I got it to open up pages in an iframe in about 15min so I would say it was pretty straight forward.

I think I am going to go ahead and use it for the editing portions.

At this point I have not used very much Javascript except for Ajax update panels. Should you just assume that most browsers have Javascript enabled?

The site I am working on now is not going to be used for commercial purposes so I am not going to worry about the few users who might disable JS but when you design sites, do you make every feature work without the use of Javascript? Is that even worth doing? (I'd imagine it would be a pain in the ass)


Thanks for the fancybox reference.
 
Old May 20th, 2012, 05:57 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't have any statistics, but I think the number of people with JavaScript disabled is quite low. With so many features depending on JavaScript these days, it's hard to browse the web with JavaScript disabled.

However, it all depends on your site and target audience. Some governmental rules dictate that some sites should be usable without JavaScript. So, you should use JavaScript with care, and provide fallback mechanisms. Google for "JavaScript degrade gracefully" and "JavaScript progressive enhancement" to learn more about techniques to make that work.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
IceThatJaw (May 20th, 2012)
 
Old May 22nd, 2012, 10:11 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Haven't meet that problem before.
 
Old May 22nd, 2012, 11:05 PM
Authorized User
Points: 173, Level: 3
Points: 173, Level: 3 Points: 173, Level: 3 Points: 173, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
I don't have any statistics, but I think the number of people with JavaScript disabled is quite low. With so many features depending on JavaScript these days, it's hard to browse the web with JavaScript disabled.

However, it all depends on your site and target audience. Some governmental rules dictate that some sites should be usable without JavaScript. So, you should use JavaScript with care, and provide fallback mechanisms. Google for "JavaScript degrade gracefully" and "JavaScript progressive enhancement" to learn more about techniques to make that work.

Cheers,

Imar

Hey Imar, I am having trouble repopulating my checkboxlist. I have 2 database tables, one for item colors and one for item sizes. They consist of an itemID and a size or color.

What I am trying to do grab all of the records for the item colors and item sizes by their itemID and then loop through all the checkboxes and compare them to the size or color. If they match I want to set that checkbox to selected.

I thought I had the code all figured out but it doesn't seem to work and I am having a hard time using the VS debugger. I honestly just wish I could simply output the variables to see what is going on.

This is my code:

HTML Code:
      <div class="checkboxlist">
        Sizes:
        <asp:CheckBoxList ID="CheckBoxListSizes" runat="server" 
          DataSourceID="ObjectDataSourceSizes" DataTextField="Size" DataValueField="ID">
        </asp:CheckBoxList>
      </div>
      <div class="checkboxlist">
        Colors:
        <asp:CheckBoxList ID="CheckBoxListColors" runat="server" 
          DataSourceID="ObjectDataSourceColors" DataTextField="Color" DataValueField="ID">
        </asp:CheckBoxList>
      </div>

Code:
            // get the items currently selected sizes from the database
            DavesDrums_DAL.ITEM_SIZEDataTable itemSizeDT =  itemSizeTA.GetDataByItemID(id);
            DavesDrums_DAL.ITEM_COLORDataTable itemColorDT = itemColorTA.GetDataByItemID(id);

            foreach (ListItem listItem in CheckBoxListSizes.Items)
            {
                foreach (DataRow datarow in itemSizeDT.Rows)
                {
                    if (listItem.Text.ToString() == datarow["Size"].ToString())
                       listItem.Selected = true;
                }
            }

            foreach (ListItem listItem in CheckBoxListColors.Items)
            {
                foreach (DataRow datarow in itemColorDT.Rows)
                {
                    if (listItem.Text.ToString() == datarow["Color"].ToString())
                        listItem.Selected = true;
                }
            }




EDIT - No worries! My code was correct, I just tried executing in the Page_Load event instead of the OnDataBound event. I feel so stupid!

Last edited by IceThatJaw; May 23rd, 2012 at 06:19 PM..




Similar Threads
Thread Thread Starter Forum Replies Last Post
I am having trouble with the file upload control inside a listview. IceThatJaw ASP.NET 4 General Discussion 1 March 27th, 2012 12:16 AM
ListBox inside listview andreas5 ASP.NET 4 General Discussion 0 September 30th, 2010 12:30 PM
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
CheckBox binding in ListView - Multiple events! dweezilb Windows Presentation Foundation 1 April 22nd, 2007 06:39 PM
Adding a checkbox into a listview?? pauljoy Pro VB 6 0 January 9th, 2006 08:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.