Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 24-04-2011, 09:59 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Apr 2011
Location: BBSR, Orissa
Posts: 34
Unhappy How to store multiple values of CheckBoxList? in ASP.net


I am creating a webpage using ASP.net(c#)
I have inserted a CheckBoxList inside the webpage like below

Interested in
  • Friends
  • Dating
  • Business
  • Activity Partners


where multiple values can be selected
when I click on the submit button,I want to store multiple selected values (text) in the database in a single coulmn.

and when next time the page_Load event fires,I want the multiple values to be fetched using select statement & the stored values must be selected in the CheckBoxList

My idea is to use a String datatype to store multiple values of CheckBoxList by concating & to use substring to fetch & select the multiple items
But I can't do it
Please help me...
Attached Images
File Type: png chkbox.PNG (6.7 KB, 6 views)
binay00713 is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 24-04-2011, 11:55 PM   #2 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: How to store multiple values of CheckBoxList? in ASP.net

Well, I'd say concatenate the strings using some delimiter and then split them based on that delimiter.

Say for Eg, concatenate with comma(,)

Friends,Dating,Business

Now split it with

s.Split(',');

where s is the string which contains "Friends,Dating,Business"
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 27-04-2011, 08:46 PM   #3 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: How to store multiple values of CheckBoxList? in ASP.net

> button1 = Submit
> instead using Session, query the DB

Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack && Session["data"]!=null)
            foreach (string s in Session["data"].ToString().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                foreach (ListItem l in CheckBoxList1.Items)
                    if (l.Text == s)
                        l.Selected = true;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (ListItem val in CheckBoxList1.Items)
            if (val.Selected)
                Session["data"] += val.Text + ",";

        foreach (ListItem l in CheckBoxList1.Items)
            l.Selected = false;
    }
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 28-04-2011, 12:11 PM   #4 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
Default Re: How to store multiple values of CheckBoxList? in ASP.net

@binay00713: just create a stored procedure & pass the selected values in string as ',' separated.
use column datatype a varchar
& while fetching the data use another stored procedure which returns a Table
& use split function to return comma separated values in Table form
__________________
I'm the One you've been Waiting for...
Zangetsu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:26 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2