Home All Groups Group Topic Archive Search About

DataGrid not calling ItemCommand Event

Author
11 Apr 2006 2:44 PM
Ezequiel_Pérez
Hi, I have a problem with a DataGrid, this datagrid is not calling the
ItemCommand event. I tried do to it defining the event as usual (from
the designer), but it didn't work, neither defining the event in the .aspx.

the aspx datagrid tag:

<asp:datagrid id="grdOilFields" runat="server" BorderColor="#999999"
GridLines="Vertical" HorizontalAlign="Center"
AutoGenerateColumns="False" Font-Names="Arial" Font-Size="X-Small"
CssClass="cssTabla" OnItemCommand="grdOilFields_ItemCommand">
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle Height="24px" ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Height="24px"></HeaderStyle>
<Columns>
<asp:BoundColumn HeaderText="Descripción">
<HeaderStyle Width="145px" CssClass="LeftHeaderImage"></HeaderStyle>
<ItemStyle Width="145px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<HeaderStyle Width="45px" CssClass="RightHeaderImage"></HeaderStyle>
<ItemStyle Width="45px"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="btnDelete" runat="server"
ImageUrl="../Images/Buttons/DGDelete.gif"
CommandName="btnDelete"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

the way I defined the event handler:

protected void grdOilFields_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
    ... some code which is never reached ...
}

if you have any ideas about why this event is never reached, please tell
me, thanks

Author
12 Apr 2006 8:21 PM
Alvin Bruney
do you have data available?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

Show quoteHide quote
"Ezequiel Pérez" <eaz***@gmail.com> wrote in message
news:OcAlHaXXGHA.752@TK2MSFTNGP02.phx.gbl...
> Hi, I have a problem with a DataGrid, this datagrid is not calling the
> ItemCommand event. I tried do to it defining the event as usual (from the
> designer), but it didn't work, neither defining the event in the .aspx.
>
> the aspx datagrid tag:
>
> <asp:datagrid id="grdOilFields" runat="server" BorderColor="#999999"
> GridLines="Vertical" HorizontalAlign="Center" AutoGenerateColumns="False"
> Font-Names="Arial" Font-Size="X-Small" CssClass="cssTabla"
> OnItemCommand="grdOilFields_ItemCommand">
> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
> <ItemStyle Height="24px" ForeColor="Black"
> BackColor="#EEEEEE"></ItemStyle>
> <HeaderStyle Height="24px"></HeaderStyle>
> <Columns>
> <asp:BoundColumn HeaderText="Descripción">
> <HeaderStyle Width="145px" CssClass="LeftHeaderImage"></HeaderStyle>
> <ItemStyle Width="145px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn>
> <HeaderStyle Width="45px" CssClass="RightHeaderImage"></HeaderStyle>
> <ItemStyle Width="45px"></ItemStyle>
> <ItemTemplate>
> <asp:ImageButton id="btnDelete" runat="server"
> ImageUrl="../Images/Buttons/DGDelete.gif"
> CommandName="btnDelete"></asp:ImageButton>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:datagrid>
>
> the way I defined the event handler:
>
> protected void grdOilFields_ItemCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
> ... some code which is never reached ...
> }
>
> if you have any ideas about why this event is never reached, please tell
> me, thanks
Author
12 Apr 2006 8:59 PM
Jeff Dillon
Try adding a Select command type column to the grid, from the designer

Show quoteHide quote
"Ezequiel Pérez" <eaz***@gmail.com> wrote in message
news:OcAlHaXXGHA.752@TK2MSFTNGP02.phx.gbl...
> Hi, I have a problem with a DataGrid, this datagrid is not calling the
> ItemCommand event. I tried do to it defining the event as usual (from the
> designer), but it didn't work, neither defining the event in the .aspx.
>
> the aspx datagrid tag:
>
> <asp:datagrid id="grdOilFields" runat="server" BorderColor="#999999"
> GridLines="Vertical" HorizontalAlign="Center" AutoGenerateColumns="False"
> Font-Names="Arial" Font-Size="X-Small" CssClass="cssTabla"
> OnItemCommand="grdOilFields_ItemCommand">
> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
> <ItemStyle Height="24px" ForeColor="Black"
> BackColor="#EEEEEE"></ItemStyle>
> <HeaderStyle Height="24px"></HeaderStyle>
> <Columns>
> <asp:BoundColumn HeaderText="Descripción">
> <HeaderStyle Width="145px" CssClass="LeftHeaderImage"></HeaderStyle>
> <ItemStyle Width="145px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn>
> <HeaderStyle Width="45px" CssClass="RightHeaderImage"></HeaderStyle>
> <ItemStyle Width="45px"></ItemStyle>
> <ItemTemplate>
> <asp:ImageButton id="btnDelete" runat="server"
> ImageUrl="../Images/Buttons/DGDelete.gif"
> CommandName="btnDelete"></asp:ImageButton>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:datagrid>
>
> the way I defined the event handler:
>
> protected void grdOilFields_ItemCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
> ... some code which is never reached ...
> }
>
> if you have any ideas about why this event is never reached, please tell
> me, thanks
Author
16 Apr 2006 7:47 AM
Teemu Keiski
And you databind it initially inside if(!Page.IsPostBack){...} check?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Show quoteHide quote
"Ezequiel Pérez" <eaz***@gmail.com> wrote in message
news:OcAlHaXXGHA.752@TK2MSFTNGP02.phx.gbl...
> Hi, I have a problem with a DataGrid, this datagrid is not calling the
> ItemCommand event. I tried do to it defining the event as usual (from the
> designer), but it didn't work, neither defining the event in the .aspx.
>
> the aspx datagrid tag:
>
> <asp:datagrid id="grdOilFields" runat="server" BorderColor="#999999"
> GridLines="Vertical" HorizontalAlign="Center" AutoGenerateColumns="False"
> Font-Names="Arial" Font-Size="X-Small" CssClass="cssTabla"
> OnItemCommand="grdOilFields_ItemCommand">
> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
> <ItemStyle Height="24px" ForeColor="Black"
> BackColor="#EEEEEE"></ItemStyle>
> <HeaderStyle Height="24px"></HeaderStyle>
> <Columns>
> <asp:BoundColumn HeaderText="Descripción">
> <HeaderStyle Width="145px" CssClass="LeftHeaderImage"></HeaderStyle>
> <ItemStyle Width="145px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn>
> <HeaderStyle Width="45px" CssClass="RightHeaderImage"></HeaderStyle>
> <ItemStyle Width="45px"></ItemStyle>
> <ItemTemplate>
> <asp:ImageButton id="btnDelete" runat="server"
> ImageUrl="../Images/Buttons/DGDelete.gif"
> CommandName="btnDelete"></asp:ImageButton>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:datagrid>
>
> the way I defined the event handler:
>
> protected void grdOilFields_ItemCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
> ... some code which is never reached ...
> }
>
> if you have any ideas about why this event is never reached, please tell
> me, thanks