DataGrid ItemCommand???

Discussion in 'ASP .Net' started by =?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=, Oct 22, 2004.

  1. hi all,
    i am having problem with using itemcommand of datagrid by way of asp:image
    button.
    i have put an image button in a datagrid item template and have set
    CommandName="DeleteRecord" and have coded a switch to handle the event.
    I have done this vb.net and it works fine..put in c# i can not catch the
    item command..i stepped into code
    via debug mode.. its just doest enter the dgrCaseType_ItemCommand...
    I AM TOTALLY CLULESS.....WHAT AM I MISSING...
    PLZ see code below.........

    <asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
    Width="100%" BorderWidth="2"
    BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
    AllowSorting="True" EnableViewState="True">
    <AlternatingItemStyle CssClass="bg-ltgray"></AlternatingItemStyle>
    <Columns>
    <asp:BoundColumn HeaderText="Default Owner"
    HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
    HeaderStyle-Width="150"></asp:BoundColumn>
    <asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
    HeaderStyle-Width="150" HeaderText="Options"
    ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:ImageButton ID="imgEdit" CommandName="EditRecord"
    ImageUrl="../../Images/icon_edit.gif"
    AlternateText="Edit" Runat="server"
    Height="16" Width="16"
    EnableViewState="False"></asp:ImageButton>

    <asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
    ImageUrl="../../Images/icon_trash.gif"
    AlternateText="Delete" Runat="server"
    Height="16" Width="16"
    EnableViewState="False"></asp:ImageButton>
    </ItemTemplate>
    </asp:TemplateColumn>

    </Columns>
    </asp:DataGrid>

    Then I have coded the following:

    protected System.Web.UI.WebControls.DataGrid dgrCaseType;

    protected void dgrCaseType_ItemCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    switch(e.CommandName)
    {
    case "EditRecord":
    string s=e.Item.Cells[7].Text;
    break;
    case "DeleteRecord":

    break;
    }
    }

    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    this.dgrCaseType.ItemDataBound += new
    System.Web.UI.WebControls.DataGridItemEventHandler(this.dgrCaseType_ItemDataBound);
    }

    Thanks in advance..
    -Sami.
     
    =?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=, Oct 22, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=

    Teemu Keiski Guest

    You need to wire the event handler for the DataGrid's ItemCommand event? Do
    yiou have it done in code-behind in InitializeComponent method? (It looks
    like dgrCaseType.ItemCommand += new
    DataGridCommandEventHandler(method_name);..., which seems to be missing
    there)

    If you don't have it code-behind, you can wiree it on aspx on DataGrid's
    declaration:

    .... OnItemCommand="dgrCaseType_ItemCommand" ...

    or make up similar wiring in InitializeComponent as for other events.


    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke



    "Syed Sami R. Shah" <Syed Sami R. > wrote in
    message news:...
    > hi all,
    > i am having problem with using itemcommand of datagrid by way of asp:image
    > button.
    > i have put an image button in a datagrid item template and have set
    > CommandName="DeleteRecord" and have coded a switch to handle the event.
    > I have done this vb.net and it works fine..put in c# i can not catch the
    > item command..i stepped into code
    > via debug mode.. its just doest enter the dgrCaseType_ItemCommand...
    > I AM TOTALLY CLULESS.....WHAT AM I MISSING...
    > PLZ see code below.........
    >
    > <asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
    > Width="100%" BorderWidth="2"
    > BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
    > AllowSorting="True" EnableViewState="True">
    > <AlternatingItemStyle CssClass="bg-ltgray"></AlternatingItemStyle>
    > <Columns>
    > <asp:BoundColumn HeaderText="Default Owner"
    > HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
    > HeaderStyle-Width="150"></asp:BoundColumn>
    > <asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
    > HeaderStyle-Width="150" HeaderText="Options"
    > ItemStyle-HorizontalAlign="Center">
    > <ItemTemplate>
    > <asp:ImageButton ID="imgEdit" CommandName="EditRecord"
    > ImageUrl="../../Images/icon_edit.gif"
    > AlternateText="Edit" Runat="server"
    > Height="16" Width="16"
    > EnableViewState="False"></asp:ImageButton>
    >
    > <asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
    > ImageUrl="../../Images/icon_trash.gif"
    > AlternateText="Delete" Runat="server"
    > Height="16" Width="16"
    > EnableViewState="False"></asp:ImageButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > </Columns>
    > </asp:DataGrid>
    >
    > Then I have coded the following:
    >
    > protected System.Web.UI.WebControls.DataGrid dgrCaseType;
    >
    > protected void dgrCaseType_ItemCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > switch(e.CommandName)
    > {
    > case "EditRecord":
    > string s=e.Item.Cells[7].Text;
    > break;
    > case "DeleteRecord":
    >
    > break;
    > }
    > }
    >
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    > this.dgrCaseType.ItemDataBound += new
    > System.Web.UI.WebControls.DataGridItemEventHandler(this.dgrCaseType_ItemDataBound);
    > }
    >
    > Thanks in advance..
    > -Sami.
     
    Teemu Keiski, Oct 22, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=

    Karl Seguin Guest

    first off, you aren't hooking up the ItemCommand event...you are hooking up
    the ItemDataBound however...you need this:

    this.dgrCaseType.ItemCommand+=new
    DataGridCommandEventHandler(dgrCaseType_ItemCommand);

    in your InitializeComponent (or page_load).


    Secondly, assuming you have the above, you also need to make sure that you
    aren't rebinding on postback, if so you'll lose ur event...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Syed Sami R. Shah" <Syed Sami R. > wrote in
    message news:...
    > hi all,
    > i am having problem with using itemcommand of datagrid by way of asp:image
    > button.
    > i have put an image button in a datagrid item template and have set
    > CommandName="DeleteRecord" and have coded a switch to handle the event.
    > I have done this vb.net and it works fine..put in c# i can not catch the
    > item command..i stepped into code
    > via debug mode.. its just doest enter the dgrCaseType_ItemCommand...
    > I AM TOTALLY CLULESS.....WHAT AM I MISSING...
    > PLZ see code below.........
    >
    > <asp:DataGrid ID="dgrCaseType" Runat="server" AutoGenerateColumns="False"
    > Width="100%" BorderWidth="2"
    > BorderColor="#ffffff" HeaderStyle-HorizontalAlign="Center"
    > AllowSorting="True" EnableViewState="True">
    > <AlternatingItemStyle

    CssClass="bg-ltgray"></AlternatingItemStyle>
    > <Columns>
    > <asp:BoundColumn HeaderText="Default Owner"
    > HeaderStyle-CssClass="menu_gray" DataField="CSPersonnell"
    > HeaderStyle-Width="150"></asp:BoundColumn>
    > <asp:TemplateColumn HeaderStyle-CssClass="menu_gray"
    > HeaderStyle-Width="150" HeaderText="Options"
    > ItemStyle-HorizontalAlign="Center">
    > <ItemTemplate>
    > <asp:ImageButton ID="imgEdit" CommandName="EditRecord"
    > ImageUrl="../../Images/icon_edit.gif"
    > AlternateText="Edit" Runat="server"
    > Height="16" Width="16"
    > EnableViewState="False"></asp:ImageButton>
    >
    > <asp:ImageButton ID="imgDelete" CommandName="DeleteRecord"
    > ImageUrl="../../Images/icon_trash.gif"
    > AlternateText="Delete" Runat="server"
    > Height="16" Width="16"
    > EnableViewState="False"></asp:ImageButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > </Columns>
    > </asp:DataGrid>
    >
    > Then I have coded the following:
    >
    > protected System.Web.UI.WebControls.DataGrid dgrCaseType;
    >
    > protected void dgrCaseType_ItemCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > switch(e.CommandName)
    > {
    > case "EditRecord":
    > string s=e.Item.Cells[7].Text;
    > break;
    > case "DeleteRecord":
    >
    > break;
    > }
    > }
    >
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    > this.dgrCaseType.ItemDataBound += new
    >

    System.Web.UI.WebControls.DataGridItemEventHandler(this.dgrCaseType_ItemData
    Bound);
    > }
    >
    > Thanks in advance..
    > -Sami.
     
    Karl Seguin, Oct 22, 2004
    #3
  4. =?Utf-8?B?U3llZCBTYW1pIFIuIFNoYWg=?=

    Rahim

    Joined:
    Mar 10, 2008
    Messages:
    1
    DataGrid.ItemCommand

    Hi all,
    I have a datagrid in which a link button is there.The problem is after clicking the link button it takes long time to fire the event. But the appliaction have same features in other page where it works fine. Can you suggest what to do. I have reset the iis-server too.
     
    Rahim, Mar 10, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natty Gur
    Replies:
    0
    Views:
    581
    Natty Gur
    Jun 30, 2003
  2. Mike

    DataGrid ItemCommand Event

    Mike, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    494
    Patrik Löwendahl
    Oct 24, 2003
  3. Nick Gilbert
    Replies:
    2
    Views:
    890
    Jeffrey Tan[MSFT]
    Dec 15, 2003
  4. Solomon Shaffer

    ItemCommand in DataGrid control

    Solomon Shaffer, Jan 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,765
    Solomon Shaffer
    Jan 15, 2004
  5. Mark Kelly

    Datagrid ItemCommand problems

    Mark Kelly, Jan 29, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,093
    Mark Kelly
    Jan 29, 2004
Loading...

Share This Page