<asp
ropDownList ID="DropDownList1" runat="server" DataSourceID="DataSource" DataTextField="HotelName" DataValueField="HotelId" SelectedValue='<%# Bind ("HotelId") % >'>
<asp:ListItem Value="0">Add Hotel<⁄asp :ListItem>
<⁄asp
ropDownList>
Make sure you primary Keys⁄Ids for each table start at Identity 1 and not 0, since this would cause problems with AddHotel being value of 0, and the only reason you want all tables to start at 1, is to keep it all the same since you don't want some tables to start at 0, and others at 1, since that would be confusing.
So this will generate something like this as rough sample
<asp
ropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="0">Add Hotel<⁄asp:ListItem>
<asp:ListItem Value="1">Anothe rHotel<⁄asp:ListItem>
<asp:ListItem Value="2">And Another Hotel<⁄asp:ListItem>
<asp:ListItem Value="n">N etc...<⁄asp:ListItem>
<⁄asp
ropDownList>
Since we put
DataTextField="HotelName"
This is what people would see in the DropDownList
Since we put
DataValueField="HotelId"
This is what is the Value="" would be
Since we put
SelectedValue='<%# Bind("HotelId") %>'
This is what will be stored, not the hotelName, but the HotelId for it that table
I'm guessing you have like a table with like maybe
Hotels-------⁄
--HotelID
--HotelName
And then another table something like I don't know Hmm??
Employees--⁄
--EmployeeId
--Name
--HotelId
So you would load info in a table about employees, but it's not usefull
for people to see the Foreing Key of the Employees HotelId, since you could have like
thousands of hotels, and that would be hard for people to rember all that suff, and
they would always have to have Hotels table as reference, this is why you made the DropDownlist ListItems Value=Ids
Since you have two tables Hotels, and Employees
You could make a select like this so instead of getting the Foreing key you actualy get the data the hotelName.
SELECT Employees.EmployeeId, Employees.Name, Employees.HotelId, Hotels.HotelName
FROM Employees INNER JOIN
Hotels ON Employees.EmployeeId = Hotels.HotelId
ODER BY Employees.Name ASC
This way you will not get something like this which users would not like
Employees--⁄
EmployeeId | Name | HotelId
1 | Foo Bar | 20
2 | Boo Bar | 34
You should get something like this
Employees--⁄
EmployeeId | Name | HotelId | HotelName
1 | Foo Bar | 20 | The dock
2 Boo Bar | 34 | The Inn
This way you can make a datasource, bind it to a gridview,
and edit the gridview to remove columns like EmployeeId, and HotelId.
So this way you will only see Name, and HotelName on the gridview, but you still have the other infos like EmployeeId, and HotelId to play around with for commands like delete and edit⁄update.
Want to see what I mean, just ask. I'll show you some of my source code
where I load info in a gridview, and use a formview to add⁄edit⁄update⁄delete records
From
http://www.developmentnow.com/g/8_2...dropdownlist-as-well-as-put-my-own-line-in.ht
Posted via DevelopmentNow.com Group
http://www.developmentnow.com