473,804 Members | 3,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1127
Serge,

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

/* Filter sample */

protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
bindData("1");
}

protected void DropDownList1_S electedIndexCha nged(object sender,
EventArgs e)
{
bindData(DropDo wnList1.Selecte dValue);
}

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

// Initialize Drop Down List 1
DropDownList1.D ataSource = myds.Tables["TableA"];
DropDownList1.D ataTextField = "ID";
DropDownList1.D ataValueField = "ID";

// Bind Drop Down List 1
DropDownList1.D ataBind();
DropDownList1.C learSelection() ;
DropDownList1.I tems.FindByValu e(selectedId).S elected = true;

// Initialize Drop Down List 2
DropDownList2.D ataSource = myds.Tables["TableB"];
DropDownList2.D ataTextField = "NAME";
DropDownList2.D ataValueField = "ID";

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

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

/* 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(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
bindData("1");
}

protected void DropDownList1_S electedIndexCha nged(object sender,
EventArgs e)
{
bindData(DropDo wnList1.Selecte dValue);
}

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

// Initialize Drop Down List 1
DropDownList1.D ataSource = myds.Tables["TableA"];
DropDownList1.D ataTextField = "ID";
DropDownList1.D ataValueField = "ID";

// Bind Drop Down List 1
DropDownList1.D ataBind();
DropDownList1.C learSelection() ;
DropDownList1.I tems.FindByValu e(selectedId).S elected = true;

// Initialize Drop Down List 2
DropDownList2.D ataSource = myds.Tables["TableB"];
DropDownList2.D ataTextField = "NAME";
DropDownList2.D ataValueField = "ID";

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

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

/* 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
3650
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
413
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 bound to. I though this automation is on of the purposes of the databinding ... ? What am I doing wrong ? See this little example code: using System;
8
2327
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) My app (an image viewer) opens with a Main form with a file explorer if you open the program with the exe, but opens with the ImageView form if you double click an image file, if you want to see the Main form once the ImageView is open the...
4
1313
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 name="cboCars"> <option value="0">Select a car</option> <option value="1">Ford Mustang</option> .... <option value="5">Mitsubishi Eclipse</option>
7
3585
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 a particular Seller and is read from a SellerDataview at form load. On Tabpages 2-7, the information comes from another table/another DealDataview.
7
2732
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 SqlDataAdapter and SqlDataset and loads a very simple table, with both text and integer fields. If a textbox is bound to an integer source where the current value is a valid integer, say 9, I can type in the textbox 'rubbish' and move to another...
2
1923
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 folder of c:\inetpub\wwwroot and it still does not work. Here is the error I get from it: temporary asp.net files\root\d16a94c5\8b912d73\assembly\dl2\1dc1ef5c\006575a4_827ac301\metabuilders.webcontrols.rowselectorcolumn.dll"...
0
1012
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 find myself struggling with row leave and validate events at the windows detail form level.. For row validate event I either get too many false positive for detecting rowchange/ data modification or get the delayed firing after data modification...
0
1137
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 on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the...
3
193
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, the c# cookbook does not seem to have any database stuff (it is not obvious anyway). Even committing a record is counter intuitive needing help from the newsgroup. Despite all the clever gui stuff I would not give VS a high rating for DB...
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.