S
Svein Terje Gaup
Hi,
I am trying to use a LinkButton inside a DataList control in ASP.NET
2.0. The problem is that the eventhandler for the "OnItemCommand" event
is never run.
I am using the DataList control inside a Web User Control. My
Control-directive says AutoEventWireup="true":
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="EstimateList.ascx.cs"
Inherits="GKEstimat.Units.EstimateList" %>
This is my control:
<aspataList ID="dlEstimates" runat="server"
OnItemCommand="dlEstimates_OnItemCommand" DataKeyField="ProsjektID"
ItemStyle-CssClass="listRow"
AlternatingItemStyle-CssClass="listRowAlt" >
<ItemTemplate>
<tr>
<td><asp:LinkButton CommandName="Edit" runat="server"
Text="Edit" /></td>
<td class="list"><%#DataBinder.Eval(Container.DataItem,
"ProsjektNr")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"ProsjektNavn")%></td>
<td class="list"><%#DataBinder.Eval(Container.DataItem,
"Prosjektleder")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"ProsjektlederNavn")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"StatusKode")%></td></tr>
</ItemTemplate>
</aspataList>
Here's the code:
using System;
//several "using" statements here removed from post to newsgroup
namespace GKEstimat.Units
{
public partial class EstimateList : System.Web.UI.UserControl
{
protected const string PRETEXT = "NO-GK-";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind();
}
}
protected void dlEstimates_OnItemCommand(object sender,
DataListCommandEventArgs e)
{
Trace.Write("EVENTHANDLER FOR OnItemCommand WAS HIT!");
}
protected void btnFilterByProsjektleder_Click(object sender,
EventArgs e)
{
FillList(PRETEXT + txtFilterByProsjektleder.Text,
EntityType.Prosjektleder);
}
protected void btnFilterByAvdeling_Click(object sender,
EventArgs e)
{
FillList(txtFilterByAvdeling.Text, EntityType.Avdeling);
}
private void FillList(string SearchText, EntityType entityType)
{
try
{
DataTable dt = DbHelper.ListProsjekt(SearchText,
entityType);
dlEstimates.DataSource = dt;
dlEstimates.DataBind();
DataBind();
}
catch (Exception ex)
{
LogHelper.Write(ex.Message,
LogCategoryEnum.Configuration,System.Diagnostics.TraceEventType.Error);
bool rethrow = ExceptionPolicy.HandleException(ex,
ExceptionHelper.Policy);
if (rethrow)
throw;
}
}
}
}
On the page there are two buttons outside the DataList that triggers
databinding the list. As you can see, I've not put any code into the
eventhandler yet. I'm trying get the execution to stop on a breakpoint
inside the eventhandler, but so far with no success.
Hope someone can spot what I'm doing wrong, and why the OnItemCommand
event is never run.
Sincerely
Svein Terje Gaup
I am trying to use a LinkButton inside a DataList control in ASP.NET
2.0. The problem is that the eventhandler for the "OnItemCommand" event
is never run.
I am using the DataList control inside a Web User Control. My
Control-directive says AutoEventWireup="true":
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="EstimateList.ascx.cs"
Inherits="GKEstimat.Units.EstimateList" %>
This is my control:
<aspataList ID="dlEstimates" runat="server"
OnItemCommand="dlEstimates_OnItemCommand" DataKeyField="ProsjektID"
ItemStyle-CssClass="listRow"
AlternatingItemStyle-CssClass="listRowAlt" >
<ItemTemplate>
<tr>
<td><asp:LinkButton CommandName="Edit" runat="server"
Text="Edit" /></td>
<td class="list"><%#DataBinder.Eval(Container.DataItem,
"ProsjektNr")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"ProsjektNavn")%></td>
<td class="list"><%#DataBinder.Eval(Container.DataItem,
"Prosjektleder")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"ProsjektlederNavn")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"StatusKode")%></td></tr>
</ItemTemplate>
</aspataList>
Here's the code:
using System;
//several "using" statements here removed from post to newsgroup
namespace GKEstimat.Units
{
public partial class EstimateList : System.Web.UI.UserControl
{
protected const string PRETEXT = "NO-GK-";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind();
}
}
protected void dlEstimates_OnItemCommand(object sender,
DataListCommandEventArgs e)
{
Trace.Write("EVENTHANDLER FOR OnItemCommand WAS HIT!");
}
protected void btnFilterByProsjektleder_Click(object sender,
EventArgs e)
{
FillList(PRETEXT + txtFilterByProsjektleder.Text,
EntityType.Prosjektleder);
}
protected void btnFilterByAvdeling_Click(object sender,
EventArgs e)
{
FillList(txtFilterByAvdeling.Text, EntityType.Avdeling);
}
private void FillList(string SearchText, EntityType entityType)
{
try
{
DataTable dt = DbHelper.ListProsjekt(SearchText,
entityType);
dlEstimates.DataSource = dt;
dlEstimates.DataBind();
DataBind();
}
catch (Exception ex)
{
LogHelper.Write(ex.Message,
LogCategoryEnum.Configuration,System.Diagnostics.TraceEventType.Error);
bool rethrow = ExceptionPolicy.HandleException(ex,
ExceptionHelper.Policy);
if (rethrow)
throw;
}
}
}
}
On the page there are two buttons outside the DataList that triggers
databinding the list. As you can see, I've not put any code into the
eventhandler yet. I'm trying get the execution to stop on a breakpoint
inside the eventhandler, but so far with no success.
Hope someone can spot what I'm doing wrong, and why the OnItemCommand
event is never run.
Sincerely
Svein Terje Gaup