By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,728 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,728 IT Pros & Developers. It's quick & easy.

databounded listbox with datagrid results

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.