Reputation: 273
I have drop down and grid view..i fill drop down from database like this
There is two table tblReg
and tblRes
both have RegionID
protected void Page_Load(object sender, EventArgs e)
{
T1 tea = new T1();
var list1 = tea.tblReg.ToList();
var list = (from ta in list1
let data = ta.Region + " " + ta.StartDate ?? DateTime.Now.ToString() + " " + ta.EndDate ?? DateTime.Now.ToString()
select new { data, ta.RegionID }).ToList();
if(!Page.IsPostBack)
{
regiondrop.DataSource = list;
regiondrop.DataTextField = "data";
regiondrop.DataValueField = "RegionID";
regiondrop.DataBind();
}
}
now there is several values in drop down and i want when i select value from drop down then again to this value data will be display
On dropdown SelectedIndexChange i done this
protected void regiondrop_SelectedIndexChanged(object sender, EventArgs e)
{
T1 ts = new T1();
var dq=(from dropdwn in ts.tblRes
where dropdwn.RegionID==Convert.ToInt32(regiondrop.SelectedValue)
orderby dropdwn.OwnerName
select new {
FFID = dropdwn.FFID,
OwnerName = dropdwn.OwnerName,
RegNo = dropdwn.RegNo,
RegionID = dropdwn.RegionID,
});
GridView1.DataSource = dq;
GridView1.DataBind();
}
when i select value from dropdown it shows error
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.
on
GridView1.DataBind();
any solution
Upvotes: 1
Views: 68
Reputation: 60503
Well, as your error mentions, you can't do
Convert.ToInt32(regiondrop.SelectedValue)
in a linq to entities query (it can't be translated in sql / a store expression)
So just change these lines
var dq=(from dropdwn in ts.tblRes
where dropdwn.RegionID==Convert.ToInt32(regiondrop.SelectedValue)
to
var selectedValue = Convert.ToInt32(regiondrop.SelectedValue);
var dq=(from dropdwn in ts.tblRes
where dropdwn.RegionID==selectedValue
You could also do (but the previous solution is more readable)
var dq=(from dropdwn in ts.tblRes
where SqlFunctions.StringConvert((double)dropdwn.RegionID)==regiondrop.SelectedValue
There's a method in SqlFunctions
to convert a numeric to a string, but... not a string to a numeric value.
Upvotes: 1