After creating a linq to entity query and posting the query results to a Master Grid's Data Source, how can I update the detail Grid every time a user selects a different row in the Master grid?
For e.g. in the Form Load event I call the queries.
C#
int PageID = -1;
RackEntities re = new RackEntities();
privatevoidPageList_Load(object sender, EventArgs e )
{
var pageListQuery = from p in re.pages
where p.page_id != -1selectnew { PageID = p.page_id };
GridViewPage.DataSource = pageListQuery;
var pageImageListQuery = from pi in re.page_image
where pi.page_id == PageID
select pi;
GridViewPageImage.DataSource = pageImageListQuery;
}
Then when the selection has changed in the Master Grid I want to update the Detail grid.
C#
privatevoidGridViewPage_SelectionChanged(object sender, EventArgs e )
{
var pageImageListQuery = from pi in re.page_image
where pi.page_id == //PageIDselect pi;
GridViewPageImage.DataSource = pageImageListQuery;
}
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Diptimaya PatraRank #113 · 19.8K reputationPosted Feb 15, 2010, 1:50 AM EST
0
Hi,
the below code would help you.
if(GridViewPageImage.DataSource != null)
{
GridViewPageImage.DataSource = null;
GridViewPageImage.DataSource = pageImageListQuery;
}
Thanks
Diptimaya Patra
------------------------------------------------------
MARK IT AS ANSWERED IF IT HELPS
Donnelly James46 reputationPosted Feb 15, 2010, 4:13 AM EST
0
I see how this would work if I had the current selected row's page_id but the PageListQuery is selecting more than one row so PageID would not be a single value.
Diptimaya PatraRank #113 · 19.8K reputationPosted Feb 15, 2010, 1:50 AM EST
the below code would help you.
if(GridViewPageImage.DataSource != null)
{
GridViewPageImage.DataSource = null;
GridViewPageImage.DataSource = pageImageListQuery;
}
Thanks
Diptimaya Patra
------------------------------------------------------
MARK IT AS ANSWERED IF IT HELPS
Donnelly James46 reputationPosted Feb 15, 2010, 4:13 AM EST
Donnelly James46 reputationPosted Feb 15, 2010, 9:18 AM EST
private void GridViewPage_SelectionChanged( object sender, EventArgs e ) { PageID = Convert.ToInt32( GridViewPage[ "page_id", GridViewPage.CurrentRow.Index ].Value.ToString() ); var pageImageListQuery = from pi in re.page_image join i in re.images on pi.image_id equals i.image_id join pit in re.page_image_type on pi.pit_id equals pit.pit_id where pi.page_id == PageID select new { i.image_data, pi.pi_id, pi.page_id, pi.alt_text, i.image_id, pit.pit_id, pit.pit_name, i.image_description, pi.image_desc, pi.image_order, i.width, i.height, i.file_date }; if ( GridViewPageImage.DataSource != null ) { GridViewPageImage.DataSource = null; GridViewPageImage.DataSource = pageImageListQuery; } }Thanks,
Donnelly James