Z
Zule
Hi,
I am creating a Composite Control within which I have a GridView. In
this GridView, I have three TemplateFields, the last one being a
template with a LinkButton which is meant to be clicked so I can
capture this event to do something about it. The problem is that in the
CreateChildControls method, I initialize the GridView and link its
RowCommand event to a method (so I can capture the LinkButton Click)
but it doesn't work... I put a breakpoint in the debugger in the
RowCommand handler method, but it's never called when I click the
LinkButton. Here's the code:
protected override void CreateChildControls()
{
Controls.Clear();
templateFactory = CreateTemplateFactory();
// This templateFactory is an abstractFactory I made so I can
initialize some
// default templates for the GridView programmatically
gvNextWorkItemsAndParticipants = new GridView();
gvNextWorkItemsAndParticipants.ID =
"gvNextWorkItemsAndParticipants";
gvNextWorkItemsAndParticipants.AutoGenerateColumns = false;
InitializeGridViewColumns();
gvNextWorkItemsAndParticipants.RowDataBound +=
new GridViewRowEventHandler(
gvNextTasksAndParticipants_RowDataBound );
gvNextWorkItemsAndParticipants.RowCreated +=
new GridViewRowEventHandler(
gvNextWorkItemsAndParticipants_RowCreated );
gvNextWorkItemsAndParticipants.RowCommand +=
new GridViewCommandEventHandler(
gvNextWorkItemsAndParticipants_RowCommand );
}
private void gvNextTasksAndParticipants_RowDataBound( object sender,
GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
//WorkItemBase, Task etc. are some business objects of mine
//I won't detail it here to get things simple
WorkItemBase workItem = ( WorkItemBase )e.Row.DataItem;
Label lblTask = ( Label )e.Row.FindControl( "lblTask" );
lblTask.Text = workItem.Name;
if ( !( workItem is GoldenTrack.General.WorkItems.Task ) )
{
return;
}
GoldenTrack.General.WorkItems.Task task = ( General.WorkItems.Task
)workItem;
Repeater rptParticipants = ( Repeater )e.Row.FindControl(
"rptParticipants" );
rptParticipants.ItemDataBound += new RepeaterItemEventHandler(
rptParticipants_ItemDataBound );
string membersString = task.Participants.ToString();
rptParticipants.DataSource =
GetGoldenAccessDataSource().DataSource.BulkLoad( membersString
);
rptParticipants.DataBind();
LinkButton lbtEditParticipants = ( LinkButton )e.Row.FindControl(
"lbtEditParticipants" );
bool canChooseParticipants = CanChooseParticipants( task );
lbtEditParticipants.Visible = canChooseParticipants;
lbtEditParticipants.CommandName = "EditParticipants";
lbtEditParticipants.CommandArgument = "" + task.Id;
}
}
private void gvNextWorkItemsAndParticipants_RowCreated( object sender,
GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
LinkButton lbtEditParticipants = ( LinkButton )
e.Row.FindControl( "lbtEditParticipants" );
lbtEditParticipants.ToolTip = EditParticipantsToolTip;
}
}
void gvNextWorkItemsAndParticipants_RowCommand( object sender,
GridViewCommandEventArgs e )
{
// Do Something
}
private void InitializeGridViewColumns()
{
TemplateField tasksColumn = new TemplateField();
tasksColumn.HeaderText = NextWorkItemsHeaderText;
tasksColumn.ItemTemplate = templateFactory.GetTasksChoiceTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( tasksColumn );
TemplateField participantsColumn = new TemplateField();
participantsColumn.HeaderText = ParticipantsHeaderText;
participantsColumn.ItemTemplate =
templateFactory.GetParticipantListTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( participantsColumn );
TemplateField chooseParticipantsColumn = new TemplateField();
chooseParticipantsColumn.ItemTemplate =
templateFactory.GetEditParticipantLinkTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( chooseParticipantsColumn
);
Controls.Add( gvNextWorkItemsAndParticipants );
}
Does anyone of you guys know what may be going on?
Thanks,
Zule
I am creating a Composite Control within which I have a GridView. In
this GridView, I have three TemplateFields, the last one being a
template with a LinkButton which is meant to be clicked so I can
capture this event to do something about it. The problem is that in the
CreateChildControls method, I initialize the GridView and link its
RowCommand event to a method (so I can capture the LinkButton Click)
but it doesn't work... I put a breakpoint in the debugger in the
RowCommand handler method, but it's never called when I click the
LinkButton. Here's the code:
protected override void CreateChildControls()
{
Controls.Clear();
templateFactory = CreateTemplateFactory();
// This templateFactory is an abstractFactory I made so I can
initialize some
// default templates for the GridView programmatically
gvNextWorkItemsAndParticipants = new GridView();
gvNextWorkItemsAndParticipants.ID =
"gvNextWorkItemsAndParticipants";
gvNextWorkItemsAndParticipants.AutoGenerateColumns = false;
InitializeGridViewColumns();
gvNextWorkItemsAndParticipants.RowDataBound +=
new GridViewRowEventHandler(
gvNextTasksAndParticipants_RowDataBound );
gvNextWorkItemsAndParticipants.RowCreated +=
new GridViewRowEventHandler(
gvNextWorkItemsAndParticipants_RowCreated );
gvNextWorkItemsAndParticipants.RowCommand +=
new GridViewCommandEventHandler(
gvNextWorkItemsAndParticipants_RowCommand );
}
private void gvNextTasksAndParticipants_RowDataBound( object sender,
GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
//WorkItemBase, Task etc. are some business objects of mine
//I won't detail it here to get things simple
WorkItemBase workItem = ( WorkItemBase )e.Row.DataItem;
Label lblTask = ( Label )e.Row.FindControl( "lblTask" );
lblTask.Text = workItem.Name;
if ( !( workItem is GoldenTrack.General.WorkItems.Task ) )
{
return;
}
GoldenTrack.General.WorkItems.Task task = ( General.WorkItems.Task
)workItem;
Repeater rptParticipants = ( Repeater )e.Row.FindControl(
"rptParticipants" );
rptParticipants.ItemDataBound += new RepeaterItemEventHandler(
rptParticipants_ItemDataBound );
string membersString = task.Participants.ToString();
rptParticipants.DataSource =
GetGoldenAccessDataSource().DataSource.BulkLoad( membersString
);
rptParticipants.DataBind();
LinkButton lbtEditParticipants = ( LinkButton )e.Row.FindControl(
"lbtEditParticipants" );
bool canChooseParticipants = CanChooseParticipants( task );
lbtEditParticipants.Visible = canChooseParticipants;
lbtEditParticipants.CommandName = "EditParticipants";
lbtEditParticipants.CommandArgument = "" + task.Id;
}
}
private void gvNextWorkItemsAndParticipants_RowCreated( object sender,
GridViewRowEventArgs e )
{
if ( e.Row.RowType == DataControlRowType.DataRow )
{
LinkButton lbtEditParticipants = ( LinkButton )
e.Row.FindControl( "lbtEditParticipants" );
lbtEditParticipants.ToolTip = EditParticipantsToolTip;
}
}
void gvNextWorkItemsAndParticipants_RowCommand( object sender,
GridViewCommandEventArgs e )
{
// Do Something
}
private void InitializeGridViewColumns()
{
TemplateField tasksColumn = new TemplateField();
tasksColumn.HeaderText = NextWorkItemsHeaderText;
tasksColumn.ItemTemplate = templateFactory.GetTasksChoiceTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( tasksColumn );
TemplateField participantsColumn = new TemplateField();
participantsColumn.HeaderText = ParticipantsHeaderText;
participantsColumn.ItemTemplate =
templateFactory.GetParticipantListTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( participantsColumn );
TemplateField chooseParticipantsColumn = new TemplateField();
chooseParticipantsColumn.ItemTemplate =
templateFactory.GetEditParticipantLinkTemplate();
gvNextWorkItemsAndParticipants.Columns.Add( chooseParticipantsColumn
);
Controls.Add( gvNextWorkItemsAndParticipants );
}
Does anyone of you guys know what may be going on?
Thanks,
Zule