2.6 Final (Released on June 6th, 2008 )
The tables are simple, just a User table, Project table and a link table called ProjectUser.
Here is the source of the ASP.NET 2.0 gridview:
<%@ Page Language="C#" MasterPageFile="~/MasterSubMenu.master" AutoEventWireup="true" CodeBehind="ManageProjectUsers.aspx.cs" Inherits="CatenaLogic.Website.Admin.ManageProjectUsers" %>
<asp:Content ID="defaultContent" ContentPlaceHolderID="ContentPlaceHolder" Runat="Server">
<h1>Manage project users</h1>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<llblgenpro:LLBLGenProDataSource ID="projectsDataSource" runat="server"
DataContainerType="EntityCollection"
EntityCollectionTypeName="CatenaLogic.Website.Data.CollectionClasses.ProjectCollection, CatenaLogic.Website.Data"
EnablePaging="True">
</llblgenpro:LLBLGenProDataSource>
<llblgenpro:LLBLGenProDataSource ID="projectUsersDataSource" runat="server"
DataContainerType="EntityCollection"
EntityCollectionTypeName="CatenaLogic.Website.Data.CollectionClasses.ProjectUserCollection, CatenaLogic.Website.Data"
EnablePaging="True">
<SelectParameters>
<asp:ControlParameter ControlID="projectsDropDownList" Name="ProjectId" PropertyName="SelectedValue" />
</SelectParameters>
</llblgenpro:LLBLGenProDataSource>
<p>
Project: <asp:DropDownList ID="projectsDropDownList" runat="server" AutoPostBack="true" DataSourceID="projectsDataSource" DataValueField="ProjectId" DataTextField="Name" />
</p>
<asp:GridView ID="projectUsersGridView" runat="server" AllowPaging="True"
DataSourceID="projectUsersDataSource" AutoGenerateColumns="False"
DataKeyNames="ProjectId,UserId" OnRowDataBound="projectUsersGridView_RowDataBound">
<Columns>
<asp:TemplateField>
<HeaderTemplate>User</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="userLabel" runat="server" />
<asp:ImageButton ID="editButton" ImageUrl="~/images/gridview/edit.gif" ToolTip="Edit" runat="server" />
<asp:ImageButton ID="deleteButton" ImageUrl="~/images/gridview/delete.gif" ToolTip="Delete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Here is the (relavant) code-behind:
protected void projectUsersGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 1)
{
// Get user label
Label userLabel = (e.Row.FindControl("userLabel") != null) ? (Label)e.Row.FindControl("userLabel") : null;
// Do we have a valid label?
if (userLabel != null)
{
// Get the data
ProjectUserEntity entity = (e.Row.DataItem != null) ? (ProjectUserEntity)e.Row.DataItem : null;
// Do we have a valid entity?
if (entity != null)
{
// Set up label
userLabel.Text = entity.User.ContactName;
}
}
}
}
I also have base class which takes care of the modify/delete buttons:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check row type
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get buttons
ImageButton editButton = (e.Row.FindControl(_editButtonName) != null) ? (ImageButton)e.Row.FindControl(_editButtonName) : null;
ImageButton deleteButton = (e.Row.FindControl(_deleteButtonName) != null) ? (ImageButton)e.Row.FindControl(_deleteButtonName) : null;
// Get entity base
EntityBase entity = (e.Row.DataItem != null) ? (EntityBase)e.Row.DataItem : null;
// Do we have a valid edit button?
if (editButton != null)
{
// Set command
editButton.CommandName = "CustomEdit";
// Set command arguments
if (entity != null)
{
editButton.CommandArgument = GetCommandArgument(entity);
}
}
// Do we have a valid delete button and should we confirm?
if ((deleteButton != null) && (_confirmBeforeDelete))
{
// Make sure the user should confirm
deleteButton.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this item?')");
// Set command
deleteButton.CommandName = "Delete";
}
}
}