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

Filling Dropdownlist through database values in ASP.NET 2005

19
Hello everyone,

I have three tables CompanyMst ,BranchMst and DeptMst.
CompanyMst contains:

CompanyId(Primary Key) ,CompanyName.

BranchMst contains:
CompanyId(Foreign key),BranchId(Primary Key),BranchName.

DeptMst contains:
UserId,BranchId(Foriegn key),DeptId(Primary Key),DeptName.


Now in the registration forms I am filling the DeptName and BranchName through dropdownlist using the DeptMst and BranchMst table.

Now as most of the application requires that the first item should be --Select--

But when I add DropdownList1.Items.Add("--Select--");
in page load it just overwrites the first value of the dropdownlist.

And when I tried to add the following after the databind() of dropdownlist:


objcomponent.Items.Insert(0, new ListItem("--Select", "0"));

It gives the erorr :Can't insert or update foreign key .

Please help as I know this is very small problem ,I have tried lot of things just looking for perfect solution.

Please help me to solve my problem.Please help,If anyone can explain me through coding then it will become easy for me.

Thanking you all.
Dec 2 '07 #1
4 1476
nateraaaa
663 Expert 512MB
Try adding the new item to the dropdownlist before calling DataBind().

Nathan
Dec 4 '07 #2
ITCraze
19
Thank you for replying but you know I have tried adding the item before calling databind but nothing happening.Please suggest what can I do.
Dec 5 '07 #3
nateraaaa
663 Expert 512MB
Thank you for replying but you know I have tried adding the item before calling databind but nothing happening.Please suggest what can I do.
What code did you use to try and add the item to the dropdownlist before calling DataBind()?

Did you do it like this.

Expand|Select|Wrap|Line Numbers
  1. ddlMyList.Items.Insert(0, "--Select--");
Nathan
Dec 5 '07 #4
ITCraze
19
Yes I did exactly like this.But nothing is happening.Dropdownlist is not showing Select.But If I will add this after databind() then select is visible in the dropdownlist.But on submitting the form it is giving the error of :

Cannot add or Update foreign Key BranchId.

As I have mentioned previously that my form contains two dropdownlist:

BranchName and DeptName.

BranchId is primary Key of BranchMst and BranchId is foreign key of DeptMst.

Thats why after adding ddlList.Items.Insert(0,'--Select--') after databind it is giving this kind of error.

Please help me .Iam not getting any answer to this.
Dec 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
5
by: tshad | last post by:
Here is the DropDown: <asp:DropDownList ID="ScreenTest" runat="server" /> Here is the code: ScreenTest.DataSource=objCmd.ExecuteReader ScreenTest.DataValueField="ScreenTemplateMasterID"...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
2
by: Joris De Groote | last post by:
Hi, I have a dropdownlist that contains should contain several values from the database, I fill it up in de page_load() with this code (at the end of the message) The code also adds a...
5
by: Mike | last post by:
In ASP.NET 2.0 I have a dropdownlist populated from a sqldatasource. The dropdownlist values are successfully populated from a database table. I would like to add the value "Select Company" which...
1
by: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
0
by: munya | last post by:
I am new in .asp I am trying to use dropdownlist to display values from the database and be able to query the database based on displayed values in a dropdownlist. the prob is when I select any...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.