Wednesday, October 29, 2008

Нow to dynamically change query for ListView linked to LinqDataSource?

In order to dynamically change query for ListView linked to LinqDataSource you have to handle OnSelecting event for LinqDataSource. .

For example:


protected void dsMates_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
if (Request.Params["classMateId"] != null)
{
int mateId;
if (int.TryParse(Request.Params["classMateId"], out mateId))
{
using (DataClassesPrivateMsgDataContext db = new DataClassesPrivateMsgDataContext())
{
e.Result = db.Classmates.Where(mate => mate.Id == mateId).FirstOrDefault();
}
}
}
}

How does it works you can see here: 11-A

1 comment:

Jen said...

The blog is helpfull...
visit also asp.net [c#]