简体   繁体   中英

how to pass selected row of gridview in popup window into parent page

I have 2 pages in asp.net with c# .

a parent.aspx and popup.aspx .

I passed a querystring(id) into page load of popup.aspx and used function to call row of table base on id and show gridview on popup.aspx.

now I want to select this row, and pass details into text boxes of parent.aspx that is open now. Everything is ok and row of table is passed into text boxes, but it is into new window popup of parent.aspx page, that I don't want this.

I want pass details into this page(parent.aspx) that now is open.

How can I do that.thanks.

below is my code for pass id to pop-up window

protected void btn_search_id_Click(object sender, ImageClickEventArgs e)
        {

          string str1 = Encrypt(txt_sh_p.Text);
          btn_search_id.Attributes.Add("onclick", "window.open('popup.aspx?sh_p_=" + str1 + "','Report','width=750,height=500,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=200,top=50'); return false;");

        }

my code for reading id and select row and display row in gridview on page load event of popup.aspx:

 protected void Page_Load(object sender, EventArgs e)
        {


                DAL.Sab_Ashkh sabt_ashkh = new DAL.Sab_Ashkh();
                List<DAL.Sab_Ashkh> sabt_ashkh_list;

                sabt_ashkh.sh_p = Decrypt(Request.QueryString["sh_p_"]);
                sabt_ashkh_list = sabt_ashkhDB.GetShakh_find(sabt_ashkh.sh_p);
                grid_ashkh.Visible = true;
                grid_ashkh.DataSource = grid_ashkh_list;
                grid_ashkh.DataBind();  

        }

and html code for pass row to parent page:

 <Columns>
    <asp:HyperLinkField DataTextField="id_shakh" DataNavigateUrlFields="id_shakh" DataNavigateUrlFormatString="parent.aspx?id_shakh={0}"
     HeaderText="id" ItemStyle-Width = "150" />

            <asp:TemplateField HeaderText="select">
              <ItemTemplate>
                  <asp:CheckBox ID="CheckBox1" runat="server" />
              </ItemTemplate>
              </asp:TemplateField>
    <asp:BoundField ItemStyle-Width = "150px" DataField = "sh_p" HeaderText ="kod" 
                    >

<ItemStyle Width="150px"></ItemStyle>
       </asp:BoundField>
      </Columns>

I am just telling you how you can change the variable in Main page in popup page like: Suppose Parent.aspx have:

<script type="text/javascript">
   var items =[];   
</script>

and in popup.aspx you can do something like :

window.opener.items.push(yourSelectedRows);

but as another workaround you can also use local storage like:

localStorage.setItem("selectedRecords", JSON.stringify(selectedRows));

suppose selectedRows are your array of object or anything else but as my experience the selectedRecords would be accessible in all HTML pages.

hope this help you.

Hi Aria Thanks for reply. I pass id by query string into popup window and show gridview . and this script for popup win :

     <script type="text/javascript">
     function SetName() {
         if (window.opener != null && !window.opener.closed) {
             var txtName = window.opener.document.getElementById("txt_id_mah");
             grid = document.getElementById("grid_ashkh");
             var cellPivot;
             if (grid.rows.length > 0) {
                 for (i = 1; i < grid.rows.length; i++) {
                     cellPivot = grid.rows[i].cells[1];
                     TXT.value = cellPivot;
                 }
             }
         }
         window.close();
     }
</script>     

but does not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM