![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 8
Rep Power: 0
![]() |
listbox + retreiving
hello
I have 2 listbox one of the listboxs retreives its items from an Access DB and when it is moves to the other listbox it gets saves in another tbl .. Also when the user presses on the item he should retreive all the info about it but cannot change anything ... I am trying to do it this is what i did so far ... OleDbConnection conn;
OleDbCommand cmd;
OleDbDataAdapter da;
System.Data.IDataReader BFTbl() {
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\Inetpub\\HASE" +
"M\\HASEM.mdb";
System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);
string queryString = "SELECT [tblNewItems].[strName], [tblNewItems].[Date], [tblNewItems].[AWB] FROM [t" +
"blNewItems]";
System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;
dbConnection.Open();
System.Data.IDataReader dataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
return dataReader;
}
private void Button1_Click(object sender, System.EventArgs e)
{
string strSelection;
if (ListBox1.SelectedItem != null)
{
strSelection = ListBox1.SelectedItem.Text;
if (ListBox2.Items.FindByText(strSelection)== null )
{
ListBox2.Items.Add(strSelection);
ListBox2.SelectedIndex =0;
ListBox1.Items.Remove(strSelection);
}
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
string strSelection;
if (ListBox2.SelectedItem != null)
{
strSelection = ListBox2.SelectedItem.Text;
if (ListBox1.Items.FindByText(strSelection)== null )
{
ListBox1.Items.Add(strSelection);
ListBox1.SelectedIndex =0;
ListBox2.Items.Remove(strSelection);
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//Put user code to initialize the page here
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\HASEM\\HASEM.mdb;");
cmd = new OleDbCommand("select strName from tblNewItems",conn);
da= new OleDbDataAdapter(cmd);
Dim dsColor = new DataSet();
da.Fill(dsColor);
ListBox1.DataSource = dsColor;
ListBox1.DataTextField = "strName";
ListBox1.DataBind();
ListBox1.SelectedIndex = 0;
}
}
</script>Please I need your help I have like 10 more pages to validate in 2 weeks and it is a very short time :cry2: |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Feb 2005
Location: PA, USA
Posts: 253
Rep Power: 4
![]() |
could you please state the problems you are having with your code? what don't you know how to do? you said what you were trying to do but didn't say what you were having trouble with.
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2006
Posts: 8
Rep Power: 0
![]() |
I don't know how to do this
when the user presses on an item in listbox the details about the item should be retreived |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Feb 2005
Location: PA, USA
Posts: 253
Rep Power: 4
![]() |
if i were you i would probably store an object in each list item's tag property. This object will contain all of the data you need to populate the other box with the details of that particular item.
if you don't understand what i mean, let me know and i'll try to explain it better. when you do your initial query to populate the listbox items, get all of the other data as well and stick it in an object and store it in the tag. that's how i do stuff like this.
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|