Thursday, November 6, 2008

Example of GridView Architecture

I'm pasting this code snippet in for posterity. I had intended to make use of the RowDataBound event to alter Web Controls nested within the rows of a GridView.

I successfully obtained all the properties I needed. In the final implementation, the code will be in the main constructor. This is due to the lack of a GridView in its entirety as GridViewRow events are called.

protected void PhotoGalleryGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (!IsPostBack)
{
//Test to see which Row was bound for each RowDataBound event
GridView theGridView = (GridView)sender;

//get rownum for the event
int myRow = e.Row.RowIndex;

//init rowID to value of 0
int rowID = 0;

//if rownum is a body row, run the operation
if (myRow > -1)
{
//get the ID to associate
rowID = int.Parse(theGridView.DataKeys[myRow].Value.ToString());
int numRows = PhotoGalleryGridView.Rows.Count;

//locate the checkboxlist
CheckBoxList CheckBoxList1 = (CheckBoxList)PhotoGalleryGridView.Rows[myRow].FindControl("NonEditableCheckBoxList");
CheckBoxList CheckBoxList2 = (CheckBoxList)PhotoGalleryGridView.Rows[myRow].FindControl("EditableCheckBoxList");

//create an API for testing values
ApplicationAssociationsBLL appAssociationsAPI = new ApplicationAssociationsBLL();
ImperialConcrete.ApplicationAssociationsDataTable associations = appAssociationsAPI.GetApplicationAssociationsByPhotoID(rowID);
//ImperialConcrete.ApplicationAssociationsRow association = associations[0];

//update the values for the lists
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
//Get CheckBoxAttributeID for sql operation
int CheckBoxID = int.Parse(CheckBoxList1.Items[i].Value);
foreach (ImperialConcrete.ApplicationAssociationsRow association in associations)
{
if (association.ApplicationID == CheckBoxID)
{
CheckBoxList1.Items[i].Selected = true;
break;
}
else
CheckBoxList1.Items[i].Selected = false;
}
}
}
int stopper = 1;
}
}

Monday, November 3, 2008

flying colors

A custom asp.net module by nathanaeljones.com was a propos for working with stored images on this project. He also customized it for me so I could use datastreams to resize images dynamically. Highly recommended A+++;

Next order of business:

Work on batch methods to clear all Foreign Key Associations when performing record deletes.