Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,


I have a requirement where I need to view records of a table in a POPUP window from an Entry form.When we select a particular client from dropdownlist, the Gridview Populates.On selecting a row, the records populate on Entry from.

my code is below:


.aspx:--

ASP.NET
<body>
    <form id="form1"  runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        
 
    <asp:UpdatePanel ID="UpdatePanel2" runat="server"  UpdateMode ="Always" >
    <contenttemplate>
    
    <div>
       <table>
       <tr>
       <td>Enter Name</td>
       <td>
        <asp:TextBox ID="txtname" runat="server" Height ="30px" Width ="200px" Font-Size ="15px" 
            Font-Names ="Tahoma" CssClass="lowercase" >
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" SetFocusOnError ="true"  ControlToValidate ="txtname" ValidationGroup ="vg1"   ErrorMessage="Fields Required<br />Name Required"  Display="None" >
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" HighlightCssClass ="validatorCalloutHighlight" runat="server" TargetControlID ="RequiredFieldValidator1">
         <animations>
        <onshow>
        <sequence>
        <hideaction visible="true" />
        <fadein duration="1" minimumopacity="0" maximumopacity="1" />
        </sequence>
        </onshow>
        <onhide>
        <sequence>
        <fadeout duration="1" minimumopacity="0" maximumopacity="1" />
        <hideaction visible="false" />
        </sequence>
        </onhide>
    </animations>
        
        </td>
    </tr>
    <tr>
    <td class="requiredFields ">Address</td>
    <td>
        <asp:TextBox ID="txtaddress" runat="server" Height ="30px" Width ="200px" Font-Names ="Tahoma" Font-Size ="15px">
         <asp:RequiredFieldValidator ID="RFVadd" runat="server" SetFocusOnError ="true"  ControlToValidate ="txtaddress" ValidationGroup ="vg1"   ErrorMessage="Fields Required<br />Name Required"  Display="None" >
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender4" WarningIconImageUrl ="~/Images/red-skull-md.png" HighlightCssClass ="validatorCalloutHighlight" runat="server" TargetControlID ="RFVadd">
         <animations>
        <onshow>
        <sequence>
        <hideaction visible="true" />
        <fadein duration="1" minimumopacity="0" maximumopacity="1" />
        </sequence>
        </onshow>
        <onhide>
        <sequence>
        <fadeout duration="1" minimumopacity="0" maximumopacity="1" />
        <hideaction visible="false" />
        </sequence>
        </onhide>
    </animations>
        
        
        </td>
    </tr>
    <tr>
    <td class="requiredFields">Contact No</td>
    <td>
        <asp:TextBox ID="txtcontactno" runat="server" Height ="30px" Width ="200px" Font-Names ="Tahoma" Font-Size ="15px">
        <asp:RequiredFieldValidator ID="RFVContactNo" runat="server" ControlToValidate ="txtcontactno" SetFocusOnError ="true"   Display="None" ValidationGroup ="vg1"   ErrorMessage="Fields Required<br />Email Id Required">
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" WarningIconImageUrl ="~/Images/icon-warning1.png" HighlightCssClass ="validatorCalloutHighlight"   TargetControlID ="RFVContactNo" >
        <animations>
        <onshow>
        <sequence>
        <hideaction visible="true" />
        <fadein duration="1" minimumopacity="0" maximumopacity="1" />
        </sequence>
        </onshow>
        <onhide>
        <sequence>
        <fadeout duration="1" minimumopacity="0" maximumopacity="1" />
        <hideaction visible="false" />
        </sequence>
        </onhide>
    </animations>
        
        
        </td>
    </tr>


    <tr>
    <td class="requiredFields">Email</td>
    <td>
        <asp:TextBox ID="txtemail" runat="server" Height ="30px" Width ="200px" Font-Size ="15px"  Font-Names ="Tahoma">
        <asp:RequiredFieldValidator ID="RFVEmail" runat="server" ControlToValidate ="txtemail" SetFocusOnError ="true"   Display="None" ValidationGroup ="vg1"   ErrorMessage="Fields Required<br />Email Id Required">
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" WarningIconImageUrl ="~/Images/red-skull-md.png" HighlightCssClass ="validatorCalloutHighlight"   TargetControlID ="RFVEmail" >
        <animations>
        <onshow>
        <sequence>
        <hideaction visible="true" />
        <fadein duration="1" minimumopacity="0" maximumopacity="1" />
        </sequence>
        </onshow>
        <onhide>
        <sequence>
        <fadeout duration="1" minimumopacity="0" maximumopacity="1" />
        <hideaction visible="false" />
        </sequence>
        </onhide>
    </animations>
        
        </td>
    </tr>

    
    <tr>
    <td class="requiredFields">Fax</td>
    <td>
        <asp:TextBox ID="txtfax" runat="server" Height ="30px" Width ="200px" Font-Names ="Tahoma" Font-Size ="15px">
        <asp:RequiredFieldValidator ID="RFVFax" runat="server" SetFocusOnError ="true"  ControlToValidate ="txtfax" ValidationGroup ="vg1"   ErrorMessage="Fields Required<br />Name Required"  Display="None" >
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" HighlightCssClass ="validatorCalloutHighlight" runat="server" TargetControlID ="RFVFax">
         <animations>
        <onshow>
        <sequence>
        <hideaction visible="true" />
        <fadein duration="1" minimumopacity="0" maximumopacity="1" />
        </sequence>
        </onshow>
        <onhide>
        <sequence>
        <fadeout duration="1" minimumopacity="0" maximumopacity="1" />
        <hideaction visible="false" />
        </sequence>
        </onhide>
    </animations>
        
        
        </td>
    </tr>
    <tr>
        <td class="requiredFields">
            A/C Head
        </td>
        <td>
             <asp:DropDownList ID="ddlaccode" runat="server" CssClass ="ddl ">
        <asp:ListItem Text ="Select" Value ="0">
        
        
        </td>
    </tr>
    <tr>
        <td colspan="2" id="msg"  runat="server" class="msgstyle">
            
        
    </tr>

       
       </table>
      <asp:Button ID="btnview" runat="server" Text="Button" />
    </div>
    <div>
       
         <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" DropShadow ="true"  
        DynamicServicePath="" Enabled="True" TargetControlID="btnview" cancelcontrolid="ImageButton1" okcontrolid="btnOkay" OnOkScript ="ok()"
	 popupcontrolid="Panel2"  
	popupdraghandlecontrolid="PopupHeader" drag="true" 
	backgroundcssclass="ModalPopupBG">
        
              <asp:Panel ID="Panel2" runat="server" style="display: none">
               
                 
             
	<div class="HellowWorldPopupmore">

               
                <div style=" max-width : 950px; font-family : Tahoma ;font-weight :200 ;">
         <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode ="Conditional" >
        <contenttemplate>
         <table>
         <tr>
         <td id="hdr">
                 style =" height : 35px; font-size :large ; color :Purple ; font-weight :bold ; border-bottom-color :Aqua ; border-bottom-style :solid ; border-bottom-width : 1px;">
<div style="float :right ;">         <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl ="~/clzo.jpg" CssClass ="cls"    /></div>
         </td>
         
         </tr>
         <tr>
         <td>
             <asp:DropDownList ID="ddlclub" runat="server" OnSelectedIndexChanged ="ddlclub_SelectedIndexChanged" AutoPostBack ="true" >
             
         </td>
         </tr>
         <tr>
         <td>

             <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false" onrowcreated="GridView1_RowCreated" 
                    onrowdatabound="GridView1_RowDataBound" 
                    onselectedindexchanged="GridView1_SelectedIndexChanged" 
            DataKeyNames="code" >
                <columns>
                 <asp:BoundField DataField="code" HeaderText="code"   
                     ReadOnly="True" SortExpression="code" />
                     <asp:BoundField DataField="clubname" HeaderText="clubname"   
                     ReadOnly="True" SortExpression="clubname" />
                     <asp:BoundField DataField="Add1" HeaderText="Address"   
                     ReadOnly="True" SortExpression="Add1" />
                      
                 <asp:BoundField DataField="Phone" HeaderText="Phone" 
                     SortExpression="Phone" />
                 <asp:BoundField DataField="FAX" HeaderText="FAX" 
                     SortExpression="FAX" />
                 <asp:BoundField DataField="Email" HeaderText="Email"   
                     ReadOnly="True" SortExpression="Email" />
                       <asp:BoundField DataField="Accode" HeaderText="Accode"   
                     ReadOnly="True" SortExpression="Accode" />
                       <asp:BoundField DataField="UserCd" HeaderText="UserCd"   
                     ReadOnly="True" SortExpression="UserCd" />
                 
                     
                 
             </columns>
             
         </td> 
         </tr>
         </table> 
         </contenttemplate>
     <triggers>
     
     <asp:AsyncPostBackTrigger ControlID ="ddlclub" EventName ="SelectedIndexChanged" /></triggers>
      
         <div class="clear"> </div>
                </div>
                <div>
                    <input id="btnCancel" type="button" value="Close" style =" border-style :none ; background-color :White ; display :none ;" />
                    <input id="btnOkay" type="button" value="" style =" border-style :none ; background-color :White ; display : none ;"   />
                    
		</div>
        
        </div> 
    
       
    
       
    
       </div>
       </contenttemplate>
       <triggers>
        <asp:AsyncPostBackTrigger ControlID ="ddlclub" EventName ="SelectedIndexChanged" /></triggers>
            
    
    </form>
</body>



.cs code:---

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           bindclub();
       }
   }

   protected void bindclub()
   {
       con.Open();

       SqlCommand cmd;
       try
       {
           cmd = new SqlCommand("Select code,clubname from club", con);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           ddlclub.DataValueField = "code";
           ddlclub.DataTextField = "clubname";
           ddlclub.DataSource = dt;
           ddlclub.DataBind();

       }
       catch (Exception ex)
       {

       }
       finally
       {
           con.Close();
       }

   }


   protected void bindgrid()
   {
       con.Open();
       SqlCommand com;
       try
       {
           com = new SqlCommand("Select * from Club where code='" + ddlclub .SelectedValue  + "' ", con);
           SqlDataAdapter daa = new SqlDataAdapter(com);
           DataTable dtt = new DataTable();
           daa.Fill(dtt);
           GridView1.DataSource = dtt;
           GridView1.DataBind();
       }
       catch (Exception ex)
       {
           con.Close();
       }
   }
   protected void ddlclub_SelectedIndexChanged(object sender, EventArgs e)
   {
       bindgrid();
       ModalPopupExtender1.Show();
       UpdatePanel1.Update();
   }

   protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
           e.Row.Style.Add("cursor", "pointer");
       }
   }
   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       e.Row.Cells[0].Visible = false;
     //  e.Row.Cells[1].Visible = false;
      // e.Row.Cells[2].Visible = false;
      // e.Row.Cells[5].Visible = false;
   }
   protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
   {


       ViewState["code"] = GridView1.SelectedRow.Cells[0].Text; ;



   }



The Problem is that, after we select a Grid row, all the records populate as intended but the popup window in freezed at the fag end of the page.


Please help....

Posted
Updated 22-Apr-14 8:59am
v3
Comments
ZurdoDev 21-Apr-14 14:05pm    
You need to simplify this post. This is a lot of code and no one will likely look through it all to figure out the issue.
Herman<T>.Instance 22-Apr-14 14:59pm    
what is itching you?

1 solution

Why not just call ModalPopupExtender1.Hide() in your SelectedIndexChanged event handler of the gridview?

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
 {
      ViewState["code"] = GridView1.SelectedRow.Cells[0].Text; ;
      ModalPopupExtender1.Hide();
 }
 
Share this answer
 
Comments
abatechcal_sreya 24-Apr-14 3:04am    
ModalPopupExtender1.Hide() is not being able to hide the modal popup
Richard C Bishop 24-Apr-14 9:51am    
Ok, is it throwing any exceptions?
abatechcal_sreya 25-Apr-14 2:14am    
nope...the entire pop up panel is staying in the fag end of the page...
it is for update panel?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900