Getting row id value works and does not work

3 posts, 0 answers
  1. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 08 Nov Link to this post

    I have a grid with two buttons on each row, open and remove. Using OnItemCommand click the button goes to the code fine, the remove button works fine but the open button always gets the id from the first row.

    This is the code that creates the two buttons, the same except for the names and images.

                        GridButtonColumn gridButtonColumn = new GridButtonColumn();
                   gridButtonColumn.ButtonType = GridButtonColumnType.ImageButton;
                   gridButtonColumn.ImageUrl = "~/Images/OpenLinkIcon.png";
                   gridButtonColumn.CommandName = "OpenLink";
                   gridButtonColumn.UniqueName = "OpenLink";
                   gridButtonColumn.Text = "Open Signup Template";
                   gridButtonColumn.Display = true;
                   gridButtonColumn.HeaderText = "";
                   gridButtonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                   gridButtonColumn.HeaderStyle.Width = Unit.Pixel(40);
                   signupGrid.MasterTableView.Columns.Add(gridButtonColumn);

     

                   gridButtonColumn = new GridButtonColumn();
                   gridButtonColumn.ButtonType = GridButtonColumnType.ImageButton;
                   gridButtonColumn.ImageUrl = "~/Images/DeleteIcon.png";
                   gridButtonColumn.CommandName = "Delete";
                   gridButtonColumn.UniqueName = "Delete";
                   gridButtonColumn.Text = "Remove Signup Template";
                   gridButtonColumn.Display = true;
                   gridButtonColumn.HeaderText = "";
                   gridButtonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                   gridButtonColumn.HeaderStyle.Width = Unit.Pixel(40);
                   signupGrid.MasterTableView.Columns.Add(gridButtonColumn);

     

    This is the asp grid definition

    <div id="GridDiv" runat="server" >
        <asp:panel runat="server" ID="Panel1"  CssClass="windowPercent" >
            <telerik:RadGrid runat="server" ID="SignupGrid" OnItemCommand="Grid_ItemCommand"></telerik:RadGrid>                 
        </asp:panel>
    </div>

     

    And  this the aspx.cs code for the Grid_ItemCommand.

    protected void Grid_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (isPageRefresh || e == null || e.Item == null) {
            return;
        }
        
        GridDataItem item = (GridDataItem)e.Item;
        string strId = item[SignupListData.FIELD_ID].Text;
        switch (e.CommandName) {
            case "Delete":
                string name = item[SignupListData.FIELD_NAME].Text;
                lblConfirm.Text = "Are you sure you want to remove sigup template \"" + name + "\"?";
                RemoveSignup.Value = "Yes";
                RemoveId.Value = strId;
                break;
            case "OpenLink":
                this.Response.Redirect("/Signup/Design/" + strId);
                break;
        }
    }

     

    The strId  and name values for Delete is the proper one for the row, while the strId for OpenLink is always the FIELD_ID from the first row,

    Searching the forums  and examples I found several different ways of getting the field id value but none of them worked.

    No idea how to fix this problem.

    George

    FYI: the form to post this to the forum has a buggy edit box.  If I backspace once its works but further ones will skip to the front of words removing spaces unexpectedly.  It was rather difficult to make this post.

  2. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 08 Nov in reply to George Link to this post

    Now this is really silly. 

    gridButtonColumn.CommandName = "Delete";
    gridButtonColumn.UniqueName = "Delete";

     

    The button that has the CommandName and UniqueName of "Delete" can get the correct id and name fields but any other names I put in result in the id and name of the first row being returned.   For the moment I am using the "Delete" name for open since I need to open things for my development but remove now fails since it always gets the first row.  I tried various names such as xxx, x, y, Open, Close, Remove with no luck, only Delete works.

    This is truly bizarre behavior.  If there are some other magic strings that work please let me know, I really need two buttons.

    George

     

     

    The backspace problem in this window is gone now, that was weird too.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. George
    George avatar
    73 posts
    Member since:
    Oct 2014

    Posted 08 Nov in reply to George Link to this post

    Going through the examples I found the command name "Select" which works and is even an appropriate value for open.

    I know you will not be able to reproduce this as usual, but honest it is really happening. Visual Studio 2013 Version 12.0.31101.00 Update 4 with up to date Asp.Net Ajax.

    George

Back to Top