473,394 Members | 1,787 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,394 software developers and data experts.

Help on simple databinding ???

Dear all,

I have 2 tables from which I create a simple data relation:
Table1 has a field name ID which is retrive from a database
Table2 has fields ID and Name which is retrived from database

I have build a datarelation from Table 1 to Table 2 on field ID, so far so
good
Base on that my dataset contains following structure :

TABLE1: ID
TABLE2: ID, NAME

From that I have 2 list box name lstTable1 and lstTable 2
What I need to do is :
- bind the lstTable1 listbox on ID field of table 1 from dataset
- bind the lstTable2 listbox on field NAME and gets childs content field
issue from content of lstBox1

I am able to bind list box but the content of lstBox' contains all records
and NOT only records based on parent of lstBox1

How can I do that ?

thnaks for your help
regards
Serge
Mar 28 '06 #1
2 1115
Serge,

One approach is to use a row filter on the second list. Here's some
sample code:

/* Filter sample */

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
bindData("1");
}

protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
bindData(DropDownList1.SelectedValue);
}

private void bindData(string selectedId)
{
DataSet myds = GetDataSet();

// Initialize Drop Down List 1
DropDownList1.DataSource = myds.Tables["TableA"];
DropDownList1.DataTextField = "ID";
DropDownList1.DataValueField = "ID";

// Bind Drop Down List 1
DropDownList1.DataBind();
DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue(selectedId).Select ed = true;

// Initialize Drop Down List 2
DropDownList2.DataSource = myds.Tables["TableB"];
DropDownList2.DataTextField = "NAME";
DropDownList2.DataValueField = "ID";

// Apply Filter to Drop Down List 2
myds.Tables[1].DefaultView.RowFilter =
string.Format("ID = {0}", selectedId);

// Bind Drop Down List 2
DropDownList2.DataBind();
}

/* End sample */

I simplified it a bit, but you can see that when the page loads or the
first DropDownList's index changes the second list is filtered.

-Carl

Mar 28 '06 #2
hi carl, thanks

the idea was to use the dtarelation object.
I manage to get it working

serge

"carl" wrote:
Serge,

One approach is to use a row filter on the second list. Here's some
sample code:

/* Filter sample */

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
bindData("1");
}

protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
bindData(DropDownList1.SelectedValue);
}

private void bindData(string selectedId)
{
DataSet myds = GetDataSet();

// Initialize Drop Down List 1
DropDownList1.DataSource = myds.Tables["TableA"];
DropDownList1.DataTextField = "ID";
DropDownList1.DataValueField = "ID";

// Bind Drop Down List 1
DropDownList1.DataBind();
DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue(selectedId).Select ed = true;

// Initialize Drop Down List 2
DropDownList2.DataSource = myds.Tables["TableB"];
DropDownList2.DataTextField = "NAME";
DropDownList2.DataValueField = "ID";

// Apply Filter to Drop Down List 2
myds.Tables[1].DefaultView.RowFilter =
string.Format("ID = {0}", selectedId);

// Bind Drop Down List 2
DropDownList2.DataBind();
}

/* End sample */

I simplified it a bit, but you can see that when the page loads or the
first DropDownList's index changes the second list is filtered.

-Carl

Mar 28 '06 #3

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

Similar topics

4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
0
by: Robert Ludig | last post by:
How do I bind a textbox to a simple string varaible with databinding? I managed to do the binding but unfortnatedly the textvox does not get updated when I change the string wich the textbox is...
8
by: Tim Geiges | last post by:
Since I am being challenged with learning c# I figured I could pass some of the pain on to you guys :-) I have another question(this one is important for me to fix before I can get my app to Beta)...
4
by: Dan | last post by:
I'm databinding my DropDownList to a DataSet. How do I add a dummy record at the top of the combo box. In other words, suppose we are dealing with cars I want something like: <select...
7
by: Richard | last post by:
I have a form with seven tapages. These span only one record with a large number of fields (textboxes). On Tabpage1 I display a number of read-only text boxes. This displays information about...
7
by: Justin Hoffman | last post by:
I am new to vb.net programming and am just exploring the way databinding works with Windows forms and am having trouble with some fairly basic customization of data entry. The form uses the...
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
0
by: GS | last post by:
I definitely feel I don't have the basic understanding of windows form databinding for dotnet 2 or 3 despite reading the msdn power point on windows form data binding notes In particular, I...
0
by: opedog | last post by:
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done...
3
by: Ken Foskey | last post by:
I am a new VS and C# developer with 20 plus years programming experience and I am finding the database stuff incredibly frustrating. I have read programming c# 3.0 pretty much cover to cover, ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.