Click here to Skip to main content
14,922,560 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to update a table where state_id and city_id have int data type stored.
but when the user loggs in his details are displayed. but the problem is that when he sees his state , and city so the user can only see stat_id and city_id. as 1 or 2... or so on..
but i want selected state name and city name to be displayed instead of state_id, city_id.
and i used detailsview.

1 solution

You must have bound your columns to State ID and City ID. That is why it is showing State ID and City ID.
You must know that computer is very dumb and does whatever you ask it to do.
Member 9671810 25-Mar-13 8:29am
yup... but the table contains State_id and city_id... as a foreign key
Ankur\m/ 25-Mar-13 8:30am
So get the State name and city name and bind your datalist to these columns and it will show the names. As simple as that!
Member 9671810 25-Mar-13 8:40am
note:" it is detailsview so here the user can update it"
Member 9581488 25-Mar-13 9:13am
Try Joining two table. (say for exp:- userdetails and StateDetails join them with stateid)
Are you using dropdown for displaying that??
Ankur\m/ 25-Mar-13 12:38pm
Step 1: Get required column from your database. Update the query if they are already not coming in the record set.
Step 2: Change the databound column to the corresponding state and city name column.
I don't understand what the problem is. If you need more help with this you will have to post your code here.
Member 9671810 25-Mar-13 13:15pm
<asp:BoundField DataField="user_id" HeaderText="USER ID" ReadOnly="True" />
<asp:BoundField DataField="firstname" HeaderText="FIRST NAME" />
<asp:BoundField DataField="lastname" HeaderText="LAST NAME" />
<asp:BoundField DataField="username" HeaderText="USERNAME" />
<asp:BoundField DataField="state_id" HeaderText="STATE" />
<asp:BoundField DataField="city_id" HeaderText="CITY" />
<asp:BoundField DataField="pincode" HeaderText="PINCODE" />
<asp:BoundField DataField="mobile_no" HeaderText="MOBILE NO" />
<asp:BoundField DataField="phone_no" HeaderText="PHONE NO." />
<asp:BoundField DataField="e_mail" HeaderText="E-MAIL" />
<asp:BoundField DataField="address" HeaderText="ADDRESS" />
<asp:BoundField DataField="reg_date" HeaderText="REGISTRATION DATE" />
<asp:CommandField ShowEditButton="True" />

i have the following fields to be displayed in detailsview.
but here state_id and city_id is shown and they are foreign keys.
and i want to display name of their selected state_id and city_id
Member 9581488 25-Mar-13 15:44pm
I suggest you to use join for displaying statename and cityname.
here You are binding it with state_id and city_id so of course, it will bind it with that value only.
1) Join 2 tables
2) bind your required field to your webcontrols
3) I suppose your end user is able to edit the records. So for that You have to use edit template where you have boundfields for cityid and stateid.
Member 9671810 27-Mar-13 6:23am
i tried 1) and 2) step of yours but i dint get your 3) step.
Member 9581488 27-Mar-13 10:15am
You have boundfield for stateid and cityid...
But when user edits it it has to be edit if you bind your city and state with dropdown, User can modify it if you use edit template( if that is your requirement)
Ankur\m/ 26-Mar-13 5:08am
<asp:BoundField DataField="state_id" HeaderText="STATE" />
<asp:BoundField DataField="city_id" HeaderText="CITY" />
See the above code. The DataField is the database field that your column is bound to. In your case it's state and city id. Check the database query if you are already returning state and city name from database. If no, update the query to return those fields. Then replace state_id and city_id in the above code with state and city name column of your database result set. And it should be fine.
Hope this helps!
Member 9671810 27-Mar-13 6:27am
i have a table named registration. from which i fetch this columns.
and in that table i stored state_id and city_id but when we edit those columns i want state name and city name to be displayed.
Ankur\m/ 27-Mar-13 8:24am
Which table do you store state name and city name then? Use SQL 'join' to get join both tables and get state and city name. You can also have state_id and city_id. Make those field hidden/readonly. Check the databound columns properties for that.
Member 9671810 27-Mar-13 12:12pm
state and city are the 2 tables having state_id and city_id as primary key,
and that key i used as foreign key in my table named registration
if i make them read only then what if the user want to edit..?
Ankur\m/ 27-Mar-13 12:17pm
I suppose the ids are your primary key in the table. Primary key columns shouldn't be be editable by user. You won't be able to maintain the unique constraint then.
Member 9671810 27-Mar-13 12:20pm
nopes they are foregin key..(state_id and city_id)
Ankur\m/ 27-Mar-13 12:28pm
Foreign key ARE primary key from other table. And since it is a foreign key allowing it to be edited by user creates another issue of maintaining foreign key constraint (the value must be present in the parent table).
Do not allow it to be editable.
Member 9671810 27-Mar-13 12:21pm
nopes they are foreign keys(state_id and city_id)
Ankur\m/ 27-Mar-13 12:30pm
I highly recommend you read some tutorials on DetailsView and basic relational database concepts.
Member 9671810 30-May-14 14:54pm
thanks sir for your precious time.. :)

SELECT registration.user_id, registration.sname, registration.fname, registration.mname, registration.lname, registration.address, registration.bdate,
registration.age, registration.pincode, registration.occupation, registration.membership, registration.blood_id, city.city_name, state.state_name
FROM registration INNER JOIN
city ON registration.city_id = city.city_id INNER JOIN
state ON registration.state_id = state.state_id AND city.state_id = state.state_id

haha.. dis was the solution :P.. and i m stupidest among all.. :P
Member 9671810 25-Mar-13 9:24am
u mean in form..? while registering then yes...
but how in details view..? :(
Member 9581488 25-Mar-13 9:28am
It would be better if you share your code.
How you are binding your dropdown? datatextfield=?
Member 9671810 25-Mar-13 11:43am
i have bind in dropdownlist in form which is going to be filled by the user.
Member 9581488 25-Mar-13 15:45pm
To Suggest you further I require more details.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900