Solved

asp.net, c#- select data

Posted on 2009-07-03
6
314 Views
Last Modified: 2013-11-19
Hi,
I have a multiple selction dropdwn  and i need to get the options chosen.
Form code below, I need to split out each selction for each list , eg in1, in2 in the aspx c# file behind the code.

thanks
aspx.cs
***********
 protected void submitf(object sender, EventArgs e)
        {
string arg = Request.Form["in1"].ToString();
 
}
 
form
******
 <fieldset>
 
        <legend>Standard filters</legend>
        <div>
          <label for="input1">label</label>
          <select class="arc90_multiselect" multiple="multiple" id="in1" name="in1">
            <option>text</option>
            <option>text</option>
            <option>text</option>
 
          </select>
        </div>
        <div>
          <label for="input2">label</label>
          <select class="arc90_multiselect" multiple="multiple" id="in2" name="in2">
            <option>text</option>
            <option>text</option>
 
            <option>text</option>
          </select>
        </div>
        <div>
          <label for="input3">label</label>
          <select class="arc90_multiselect" multiple="multiple" id="in3" name="int3">
            <option>text</option>
 
            <option>text</option>
            <option>text</option>
          </select>
        </div>
      </fieldset>
 
<asp:Button Text="t" OnClick="submitf" runat="server" />

Open in new window

0
Comment
Question by:CharlieDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 24771480
Why don't you use Server controls.?
 
If you are using htmlcontrols then mark them runat="server"
0
 

Author Comment

by:CharlieDev
ID: 24771899
thanks, i now have


<select class="arc90_multiselect" multiple="multiple" runat="server" id="in1" name="in1">

what should i do next?
0
 

Author Comment

by:CharlieDev
ID: 24771946
I'm not sure what you mean by using server controls. Just want someway to get the submitted data.
Not sure as I want to use htmlcontrols?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 2

Expert Comment

by:nikege
ID: 24776377
Using server controls (asp:DropDownList or just html controls with runat="server") you can use these controls in codebehind.
for example:

if you use html controls your 'select' controls in codebehind will have System.Web.UI.HtmlControls.HtmlSelect type in codebehind.
If you use .Net 1.1 you should define each control in codebind you want to use
 - System.Web.UI.HtmlControls.HtmlSelect in1;

if you use .Net 2+ you should not do it. VS will do it for you and you can use you control without any additional definition.

            IList<string> selectedValues = new List<string>();
            foreach(ListItem item in in1.Items)
            {
                if (item.Selected)
                    selectedValues.Add(item.Value);
            }

If you use server controls (asp:DropDownList) your controls will be type of System.Web.UI.WebControls.DropDownList. That is the only difrence in code behind.

0
 
LVL 2

Accepted Solution

by:
nikege earned 500 total points
ID: 24776384
The code could look something like this
protected void submitf(object sender, EventArgs e)
        {
            IList<string> in1Selected = new List<string>();
            foreach(ListItem item in in1.Items)
            {
                if(item.Selected)
                    in1Selected.Add(item.Value);
            }
 
            IList<string> in2Selected = new List<string>();
            foreach (ListItem item in in2.Items)
            {
                if (item.Selected)
                    in1Selected.Add(item.Value);
            }
 
        }

Open in new window

0
 

Author Closing Comment

by:CharlieDev
ID: 31599522
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 45
.Net remove carriage returns, line feeds and tabbs 5 36
Shared Service Environment 2 54
history of pages 7 52
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question