Dear all,
in my database i have country table
in that counrty id
countryname
i have two forms
default.aspx
--------------
heare iam binding the country name to dropdown
but dropdownlist sending the value is int
i saved this page in to db
coming to next page
View.aspx
----------
here i want bind the latest record data from database
while iam binding to page
iam binding the country but its showing to me int value(countryid) but i need to disply country name using entity freamework in asp.net
how to disply like that?
Loading

Prasad BhagatPosted Aug 14, 2014, 1:03 AM
but my question is in the first page iam saving the details to db
but in next page i want bind the values from database in page load
but when iam saving the details into db that time iam passing the country value as countryid
ex:
----
ddlcountry.datatextfield="countryname";
ddlcountry.datavaluefield="countryid";
-----------------------------
but in the next i want to disply country name
from same table
iam binding the latest record from db using select top(1) * from tablename orederby id desc
so if is there any way
Ramesh MaruthiPosted Aug 13, 2014, 11:58 AM
{
using(var dc = new DbContext())
{
dd1.DataSource = from p in dc.countries
orderby 0
select new {p.CountryName}.ToList();
dd1.DataTextField = "CountryName";
dd1.DataValueField = "CountryName";
dd1.DataBind();
}
}
or
dd1.DataSource = dc.countries.Select( p => new {p.CountryName}).Distinct().ToList();
dd1.DataTextField = "CountryName";
dd1.DataValueField = "CountryName";
dd1.DataBind();