javascript to refer runtime-created gridview

Jan 28 2008 1:29 AM

Dear all,
I have a question which is a little complicated. I want to refer  a runtime-created GridView Control through Javascript, But the GridView is placed in a PlaceHolder <asp>, the PlaceHolder <asp> is placed in a Panel <asp>. How can I use Javascript to refer to it? Thanks

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        <asp:GridView ID="gvPurchaseRequisitionApproved" runat="server" AutoGenerateColumns="False" DataKeyNames="PR_IDP,PR_IDD,PR_IDS" OnRowDataBound="gvPurchaseRequisitionApproved_RowDataBound" >
            <Columns>
                </asp:TemplateField>
                    <asp:TemplateField HeaderText="?????" ShowHeader="False">
                        <ItemTemplate>
                            <table width="100%">
                                <tr>
                                    <td width="25%">
                                        <asp:HyperLink ID="hplPopApproval" ImageUrl="~/pics/more.gif" runat="server">??</asp:HyperLink>   
                                    </td>
                                </tr>
                            </table>                                           

                       </ItemTemplate>
                    </asp:TemplateField>
            </Columns>
        </asp:GridView>

             <asp:Panel ID="pnlPopPRDApproved" style="Z-INDEX: 101; LEFT: 6px; POSITION: absolute; TOP: 613px"
            runat="server"
            Height="249px"
            Width="955px" BackColor="#FFFFC0">
                <asp:Image ID="imgClose" runat="server" ImageUrl="~/pics/close.jpg" OnClick="closePanel()"/> <br />
                <asp:PlaceHolder ID="phPlaceHolder" runat="server"></asp:PlaceHolder>                  
                <asp:HiddenField ID="hdfPR_IDP" runat="server" />
                <asp:HiddenField ID="hdfPR_IDD" runat="server" />
                <asp:HiddenField ID="hdfPR_IDS" runat="server" />

               
            </asp:Panel>  

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C# Code Behind ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /* *
     * method to init PurchaseRequisitionDApproved
     * */
    private void mb_fnInitPurchaseRequisitionDApproved(string strPR_IDP, string strPR_IDD, string strPR_IDS)
    {
        try
        {
            for (int i = 0; i < this.mb_objDataSet.Tables.Count; i++)
            {
                if (this.mb_objDataSet.Tables[i].TableName.CompareTo("tabPurchaseRequisitionDApproved") == 0)
                {
                    this.mb_objDataSet.Tables[i].Reset();
                } // end if (this.mb_objDataSet.Tables[i].TableName.CompareTo("tabPurchaseRequisitionDApproved") == 0)
            } // end for (int i = 0; i < this.mb_objDataSet.Tables.Count; i++)

            this.mb_objSqlCmdPurchaseRequisitionDApproved = new SqlCommand();
            this.mb_objSqlCmdPurchaseRequisitionDApproved.CommandType = CommandType.Text;
            this.mb_objSqlCmdPurchaseRequisitionDApproved.Connection = this.mb_objConn.pcon_sqlConnection;
            this.mb_objSqlCmdPurchaseRequisitionDApproved.CommandText = "select * from vwrPurchaseRequisitionDApproved " +
                "where " +
                "PR_IDP = '" + strPR_IDP + "' and " +
                "PR_IDD = '" + strPR_IDD + "' and " +
                "PR_IDS = '" + strPR_IDS + "'";

            this.mb_objSqlDaPurchaseRequisitionDApproved = new SqlDataAdapter(this.mb_objSqlCmdPurchaseRequisitionDApproved);
            this.mb_objSqlDaPurchaseRequisitionDApproved.Fill(this.mb_objDataSet, "tabPurchaseRequisitionDApproved");
        } // end try
        catch (Exception ex)
        {
            throw ex;
        } // end catch (Exception ex)
    } // end mb_fnInitPurchaseRequisitionDApproved()
    /* *
     * Method to bind PurchaseRequisitionDApproved to GridView
     * */
    private void mb_fnBindPurchaseRequisitionDApproved2GV(GridView gvGridView)
    {
        try
        {           
            gvGridView.DataSource = mb_objDataSet.Tables["tabPurchaseRequisitionDApproved"];
            gvGridView.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    } // end mb_fnBindPurchaseRequisitionDApproved2GV()

    protected void gvPurchaseRequisitionApproved_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            HyperLink hplHyperLink2 = (HyperLink)e.Row.FindControl("hplPopApproval");

            hplHyperLink2.Attributes.Add("onclick", "ShowMyModalPopup(" +
                "'" + gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[0] + "', " +
                "'" + gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[1] + "', " +
                "'" + gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[2] + "'" +
                ")");

            Control tempControl = LoadControl("wucPurchaseRequisitionApproved.ascx");

            GridView gvClone = new GridView();
            phPlaceHolder.Controls.Add(tempControl);


            foreach (Control ctl in phPlaceHolder.Controls)
            {
                foreach (Control ctl1 in ctl.Controls)
                {
                    if (ctl1 is GridView)
                    {
                        gvClone = (GridView) ctl1;
                        gvClone.ID = gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[0].ToString() +
                            gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[1].ToString() +
                            gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[2].ToString();
                     
                    }
                }

            } // end foreach (Control ctl in phPlaceHolder.Controls)


            mb_fnInitPurchaseRequisitionDApproved(gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[0].ToString(),
                gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[1].ToString(),
                gvPurchaseRequisitionApproved.DataKeys[e.Row.RowIndex].Values[2].ToString());
            mb_fnBindPurchaseRequisitionDApproved2GV(gvClone);

            gvClone.Style.Add("visibility", "hidden");
            // --------------------------------------------------------------------------------

        } // end if (e.Row.RowType == DataControlRowType.DataRow)
    }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%%%%%%%%% JavaScript %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ShowMyModalPopup(PR_IDP, PR_IDD, PR_IDS)
{

    var varPR_IDP = PR_IDP;
    var varPR_IDD = PR_IDD;
    var varPR_IDS = PR_IDS;

    var varPR_ID = PR_IDP + PR_IDD + PR_IDS; // this variable for concatnate GridViewID
       
    vista = (document.getElementById('pnlPopPRDApproved').style.visibility == 'hidden') ? 'visible' : 'hidden';
    document.getElementById('pnlPopPRDApproved').style.visibility = vista;

   // I want to refer RunTime created gridview here but how can I refer to runtime-created gridview that is within a Panel and within a PlaceHolder ??
    var varphPlaceHolder = document.all['phPlaceHolder'];
    varphPlaceHolder.varPR_ID.style.visibility = 'visible'; // something like this but this syntac doesn't work
    confirm(varphPlaceHolder.id);
       
    document.getElementById('hdfPR_IDP').value = varPR_IDP;   
    document.getElementById('hdfPR_IDD').value = varPR_IDD;   
    document.getElementById('hdfPR_IDS').value = varPR_IDS;   

    pos = getClick(event);
       
    document.getElementById('pnlPopPRDApproved').style.left = pos.x;
    document.getElementById('pnlPopPRDApproved').style.top = pos.y;   
   
}

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Regards,

Man Pak Hong, Dave

my hotmail: [email protected]