473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

databounded listbox with datagrid results

i have a databound listbox that has a multilple selection made to true.
when user select multiple values in listbox and clicks button i want
them to show the results in the datagrid on the same page using panels.

Jun 19 '06 #1
1 1296
the complete description of my problem is as follows:-
i have a databound listbox id "listboxcity" that has a multilple
selection made to true. when user select multiple values in listbox and
clicks button i want them to show the results in the datagrid id
"datagridname" on the same page using panels.

<script runat="server">
SqlConnection conn = new SqlConnection("user id=sa;password=;Initial
Catalog=jobsdb;Data Source=localhost;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
SqlCommand sqlcity = new SqlCommand("Select * from tbl_city",
conn);

conn.Open();
SqlDataReader citydr;
citydr = sqlcity.ExecuteReader();
listboxcity.DataSource = citydr;
listboxcity.DataBind();
citydr.Close();
}

protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
String s = "select * from tbl_job where city_code=@city_code";
SqlDataAdapter sqlda = new SqlDataAdapter(s, conn);
sqlda.SelectCommand.Parameters.Add(new SqlParameter("@city_code",
SqlDbType.Int, 4));
sqlda.SelectCommand.Parameters["@city_code"].Value =
listboxcity.SelectedValue;
DataSet ds = new DataSet();
sqlda.Fill(ds, "tbl_job");
datagridname.DataSource = ds.Tables["tbl_job"].DefaultView;
datagridname.DataBind();
}

till now it is working for single value selection and its succsseful
code is given as above. Now how to make changes in it for multiple
selection.

I have know the code that how to get multiple values from listbox by
foreach loop structure e.g

int returnselectedvalues()
{
int values = "";
foreach (ListItem li in listboxcity.Items)
{
if (li.Selected == true)
{
values += li.Value ;
}
}
return values;
}

and I think for this case SQL SELECT statement should be use with IN
key word
like e.g

USE Northwind
SELECT CompanyName, Country
FROM Suppliers
WHERE Country IN ('Japan', 'Italy','USA','UK')
With all of this case I have put it up to you dears to solveout my
problem.

Jun 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew | last post by:
Hi I just started learning wxPython I wanted to know how I could do this in wxPython self.listbox.delete(0, END) for item in self.results: self.listbox.insert(END, item)
1
by: ericm1155 | last post by:
I am trying to display some information from a database in a form that displays one record per line. When the user clicks anywhere on a line, that record is highlighted and selected, and my program...
0
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
3
by: Raja | last post by:
I have a simple question, I have a datagrid and inside the grid, i have List box. I am able to render the page with the datagrid and the lisbox values. Now, my question is how to trap the server...
2
by: Rosanne | last post by:
I have a menu written in javascript. I include that menu on an asp page. The aspx page contains both a listbox and a datagrid. There i one drop down menu that overlaps the place where the...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.