Home > Back-end >  AJAX ModalPopupExtender & Gridview row values
AJAX ModalPopupExtender & Gridview row values

Time:12-06

I've not really used the MPE before & currently have a need to, what I'm slightly confused about is losing reference to the initial control that triggers the function.

I have a gridview with a dropdownlist and onselectedindexchanged set to call a function when a value has been selected, when processed one value i grab is the RowID into a variable, out of 9 list items only one requires the pop up (Ok = proceed & Cancel = Return) & when this is triggered I lose all reference to the given grid row which is referenced via;

DropDownList ddlid = (DropDownList)sender;
GridViewRow gvrow = (GridViewRow)ddlid.NamingContainer;
RowID = (Int32.Parse(GridView1.DataKeys[gvrow.RowIndex].Values[0].ToString()));

Can anyone shed any light or have an idea on how I can keep track of the gridview row?

Thanks IchBinDicky

CodePudding user response:

One way to keep track of the gridview row would be to store the RowID value in a hidden field on the page, and then retrieve it in the function that is called by the Ok and Cancel buttons in the popup.

Here is an example of how this could be implemented:

First, add a hidden field to the page where the gridview is located, and set its Value attribute to the RowID value:

<asp:HiddenField runat="server" id="hiddenRowID" value="<%= RowID %>" /> Then, in the function that is called by the Ok and Cancel buttons in the popup, retrieve the RowID value from the hidden field, like this:

int rowID = int.Parse(hiddenRowID.Value);

This way, you can access the RowID value in the function that is called by the Ok and Cancel buttons, even though the original context (i.e. the gridview row) is no longer available.

Alternatively, you could also pass the RowID value as a parameter to the function that is called by the Ok and Cancel buttons, like this:

  functionName(RowID);

  // In the function that is called by the Ok and Cancel buttons:
  void functionName(int rowID)
  {
      // Use the rowID parameter here...
  }

This would allow you to access the RowID value without using a hidden field.

CodePudding user response:

Used session object in the code behind (point of loss) in the end as it fit a few other issues I'd encountered at the same time;

        public static string TabIndxValue
        {
            get
            {
                object value = HttpContext.Current.Session["TabIndxValue"];
                return value == null ? "" : (string)value;
            }
            set
            {
                HttpContext.Current.Session["TabIndxValue"] = value;
            }
        }

  • Related