Welcome to weblogs.com.pk Sign in | Join | Help

Master Detail with DataSourceControls

To implement master-detail using ASP.NET v2's new DataSource control; we can have two DataSource control; lets assume first is retrieving summaries and the second retrieve the detail information. The second data source will be parametric.

Lets assume there are two GridViews bound to these two data source controls. Then in the OnSelectedIndexChanged or RowCreated event of first grid view; the current row’s data-key or the selected row’ data-key value(s) are used as SelectParameter of the second data source and the second grid is binded in the same event.

protected void GridViewCurrentInventory_SelectedIndexChanged(object sender, EventArgs e)
{
 
this.ObjectDataSourceIssuedItemsSummary.SelectParameters["issuedBy"].DefaultValue =
   
this.GridViewCurrentInventory.SelectedDataKey[0].ToString();
 
this.GridViewSummary.DataBind();
}

If you are using SqlDataSource things are simple; as if detail of selected item is missing; null is passed and nothing happens; but if you are using ObjectDataSource; your woven methods should handle null values. Something like

public static DataSet GetIssuedItemsSummary(string issuedBy)
{
  
if (null == issuedBy) return null;
  
if (issuedBy.Length <= 0) return null;
  
//..
}

SqlDataSource also provides caching facility; but for ObjectDataSource; your data manager class needs to implement it; that I will discuss some time later.

Published Saturday, January 21, 2006 8:41 PM by khurram
Filed under:

Comments

No Comments

New Comments to this post are disabled