listbox selected option in asp.net

Posted by Dn2010 under ASP.NET on 5/17/2012 | Points: 10 | Views : 1046 | Status : [Member] | Replies : 1
hi friends,

i have 2 list box,

specialized area and speciallized skill

specialized area and speciallized skill listbox datas from database,


for eg,

if i click java,j2ee ,display in listbox2 -documentum to x-other from db

or

if i click Dot NET,VB,ASP,C# ,display in listbox2 -asp.net,biztalk etc from db


how to write code ,

please go through the attachement,





public void specializedarea()
{
specialarea = type.specializedarea();
int i = specialarea.Tables.Count;
DataTable dt = specialarea.Tables[0];
lst_spec_area.DataSource = dt;
lst_spec_area.DataTextField = dt.Columns[1].ToString();
lst_spec_area.DataValueField = dt.Columns[0].ToString();
lst_spec_area.DataBind();

}
public void specializedskill(string selectedarea)
{
specialskill = type.specializedskill(selectedarea);
//specialskill = type.specializedskill();
int i = specialskill.Tables.Count;
DataTable dt = specialskill.Tables[0];
lst_spec_skill.DataSource = dt;
lst_spec_skill.DataTextField = dt.Columns[1].ToString();
lst_spec_skill.DataValueField = dt.Columns[0].ToString();
lst_spec_skill.DataBind();
}

please give the solution,

thanks.




Responses

Posted by: Sriramnandha on: 5/25/2012 [Member] Starter | Points: 25

Up
0
Down
using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace LISTBOXLIST
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bind_Country();
}

public void bind_Country()
{
string constring="connectionstring";
SqlConnection con = new SqlConnection(constring);
string sqlquery="select countryname from country";

SqlDataAdapter adp=new SqlDataAdapter(sqlquery,con);
DataSet ds=new DataSet();
adp.Fill(ds);
ListBox1.DataSource=ds;
ListBox1.DataBind();

}



protected void Button1_Click(object sender, EventArgs e)
{
string constring = "connectionstring";
SqlConnection con = new SqlConnection(constring);

ListItem item = new ListItem();
item.Value = ListBox1.SelectedItem.Value;
item.Text = ListBox1.SelectedItem.Text;

// ListBox2.Items.Add(item);
// ListBox2.Items.Remove(item);


string LISTMY = item.Value;
string sqlquery = "select STATENAME,COUNTRY.COUNTRYNAME FROM STATEDETAILS INNER JOIN COUNTRY ON COUNTRY.COUNTRYID =STATEDETAILS.COUNTRYID WHERE COUNTRY.COUNTRYNAME='" + LISTMY + "'";

SqlDataAdapter adp = new SqlDataAdapter(sqlquery, con);
DataSet ds = new DataSet();
adp.Fill(ds);
ListBox2.DataSource = ds;
ListBox2.DataBind();

}
}
}


REGARDS

sriram

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response