Solved

Hide  Unhide Gridview using Javascript in Csharp 2008

Posted on 2009-05-18
3
607 Views
Last Modified: 2013-12-17
Hi,
I have this web page made in Csharp 2008. I am using a Heirarchical Gridview. It works fine but the problem is Both the parent and child gridview are shown on load where as it should show only when I click on the Link I should see the child grid view.

Could anyonw help me please.

Javascript Code:
<script type="text/javascript">
    function expandcollapse(obj, row) {
        alert(obj);
        alert(row);
        return;
        var div = document.getElementById(obj);
        var img = document.getElementById('img' + obj);
        var grdV = document.getElementById("_ctl0_MainContent_GVClaimsByBroker__ctl2_GVClaimsChild");
 
        if (div.style.display == "none") {
            div.style.display = "block";
            if (row == 'alt') {
                img.src = "~/Resources/Images/icon_minus.jpg";
            }
            else {
                img.src = "~/Resources/Images/icon_minus.jpg";
            }
            img.alt = "Close to view other Details";
        }
        else {
            div.style.display = "none";
            if (row == 'alt') {
                img.src = "~/Resources/Images/icon_plus.jpg";
            }
            else {
                img.src = "~/Resources/Images/icon_plus.jpg";
            }
            img.alt = "Expand to show Details";
        }
        //grdV.style.Attributes.Add("style,visibility:visible");
        grdV.style.display = "none";
        
    } 
    </script>
Gridview Design Code
<asp:GridView ID="GVClaimsByBroker" runat="server" AllowPaging="true" 
                AllowSorting="true" AutoGenerateColumns="false" PageSize="50" DataKeyNames="TeamID" CssClass="grid_b" Width="100%" 
                onrowdatabound="GVClaimsByBroker_RowDataBound">
            <HeaderStyle CssClass="grid_b_th" />
            <RowStyle CssClass="grid_b_td" />
            <Columns>
                <asp:TemplateField HeaderText="Sr.No">
                    <ItemTemplate>
                        <%# Container.DataItemIndex + 1%>
                    </ItemTemplate>
                </asp:TemplateField>
              <%--  <asp:BoundField HeaderText="Team Name" DataField="TeamName" />
                <asp:BoundField HeaderText="Claim Count" DataField="Claimcount" />--%>
                <asp:TemplateField HeaderText="Team Name">
                    <ItemTemplate>
                        <a href="javascript:expandcollapse('div<%# Eval("TeamID") %>','one');">
                           <img id="imgdiv<%# Eval("TeamID") %>" alt="Click to View Details for <%# Eval("TeamName") %>" width="9px" style="border:0" src="../../Resources/Images/icon_plus.jpg" />
                        <asp:Label ID="lblTeamName" runat="server" Text='<%# Bind("TeamName") %>' CssClass="content"></asp:Label>
                        </a>
                        <%--<asp:Label ID="lblTeamName" runat="server" Text='<%# Bind("TeamName") %>'></asp:Label>--%>
                    </ItemTemplate>
                    
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Claim Count">
                    <ItemTemplate>
                        <asp:Label ID="lblClmCount" runat="server" Text='<%# Bind("ClaimCount") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <tr>
                            <td colspan="100%">
                            <div id="<%# Eval("TeamID") %>">
                            <asp:GridView ID="GVClaimsChild" runat="server" Visible="false" CssClass="grid_b" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false">
                            <HeaderStyle CssClass="grid_b_th" />
                            <RowStyle CssClass="grid_b_td" />
                            <Columns>
                            <asp:BoundField HeaderText="Company Name" DataField="Companytype" />
                            <asp:BoundField HeaderText="Claim Type" DataField="ClaimType" />
                            <asp:BoundField HeaderText="Broker Name" DataField="BrokerName" />
                            <asp:BoundField HeaderText="Broker Number" DataField="BrokerNumber" />
                            <asp:BoundField HeaderText="Claim No" DataField="ClaimNumber" />
                            <asp:BoundField HeaderText="Handler Name" DataField="HandlerName" />
                            <%--<asp:TemplateField HeaderText="Company Type">
                                <ItemTemplate>
                                <asp:Label ID="lblCoType" runat="server" Text='<%# Eval("CompanyType") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Claim Type">
                                <ItemTemplate>
                                <asp:Label ID="lblClaimType" runat="server" Text='<%# Eval("ClaimType") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Broker Name">
                                <ItemTemplate>
                                <asp:Label ID="lblBrokerNM" runat="server" Text='<%# Eval("BrokerName") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Broker Number">
                                <ItemTemplate>
                                <asp:Label ID="lblBrokerNO" runat="server" Text='<%# Eval("BrokerNumber") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Claim Number">
                                <ItemTemplate>
                                <asp:Label ID="lblClaimNO" runat="server" Text='<%# Eval("ClaimNumber") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Claims Handler Name">
                                <ItemTemplate>
                                <asp:Label ID="lblHnlderNM" runat="server" Text='<%# Eval("HandlerName") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                            </Columns>
                                
                            </asp:GridView>
                            </div>
                            </td>
                        </tr>
                        
                    </ItemTemplate>
                </asp:TemplateField>   
            </Columns>
        </asp:GridView>
 
Code Behind:
protected void GVClaimsByBroker_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        BusinessLayer.Reports objRep = new BusinessLayer.Reports();
        try
        {
            GridViewRow row = e.Row;
            string strSort = string.Empty;
            string str = "";
            string handlerID="";
            if (row.DataItem == null)
            {
                return;
            }
 
            //Find Child Gridview
            GridView gv = new GridView();
            gv = (GridView)row.FindControl("GVClaimsChild");
            if (gv.UniqueID == GVUniqueId)
            {
                gv.PageIndex = gvNewPageIndex;
                gv.EditIndex = gvEditIndex;
 
                if (gvSortExpr != String.Empty)
                {
                    GetSortDirection();
                    strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir);
                }//gv.Visible = true;
                ClientScript.RegisterStartupScript(GetType(), "Expand", "<script language='Javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["TeamID"] + "','one');</script>");
            }
 
            gv.DataSource = objRep.ClaimsByBrokerReportDrilDown(((DataRowView)e.Row.DataItem)["TeamID"].ToString(), handlerID, txtFromDate.Text, txtToDate.Text, true);
 
            gv.DataBind();
            
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
The Main Grid is invoked on Click event of the Submit Button:
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        bool flag = false;
 
        try
        {
            DataSet dsReport = new DataSet();
            DataSet dsRec = new DataSet();
            string HandlerIds = "";
            string frmdate = txtFromDate.ToString();
            string toDate = txtToDate.ToString();
            HandlerIds = SelectedHandlerList();
            BusinessLayer.Reports objReports = new BusinessLayer.Reports();
  
            flag = true;
            Session["Ses_Cmdtimeout_Rep"] = "A";
            dsRec = objReports.ClaimsByBrokerReport(ComaSeperationTree(someTree, "Team"), HandlerIds, txtFromDate.Text, txtToDate.Text, flag);
            Session["Ses_Cmdtimeout_Rep"] = null;
            if (dsRec.Tables[0].Rows.Count > 0)
            {
                for (int j = 0; j < dsRec.Tables[0].Rows.Count; j++)
                {
                    GVClaimsByBroker.DataSource = dsRec;
                    GVClaimsByBroker.DataBind();
 
                    imgBtnExport.Visible = true;
                    //fillGrid();
                }
 
            }
        }
        catch (Exception ex)
        {
 
            //Response.Write(ex.ToString());
        }
 
        
    }

Open in new window

0
Comment
Question by:SriChary
3 Comments
 

Author Comment

by:SriChary
ID: 24412123
Hi,

Could Anybody please give me a solution......

Thanks
Srichary
0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 24418453
Hi SriChary,
>>..the problem is Both the parent and child gridview are shown on load where as it should show only when I click on the Link I should see the child grid view.
You can hide grid view's DIV control at start up.
eg:
<div id="<%# Eval("TeamID") %>">

Change to
<div id="<%# Eval("TeamID") %>" style="display:none">

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question