Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have dropdownlist (ddl) and repeater(rptPayment) .

on
 protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
BindRepeater();
}

Bind Repeater successfully.

In repeater when i hide and show gridview on check box checked.
It is working.

JavaScript
 function hideshowGV(itemId, itemIndex) {
            if (document.getElementById("ContentPlaceHolder1_rptPayment_chkComm_" + itemIndex).checked == true) {
                document.getElementById(itemId + "_gvPayment_" + itemIndex).style.display = 'block';
}
else {
                document.getElementById(itemId + "_gvPayment_" + itemIndex).style.display = 'none';
}
}


But when i fire another postback it (gridview) shown again even check box is not checked.

like on
ddlPaymentMode_SelectedIndexChanged


What I have tried:

ASP.NET
<table align="center" style="width: 100%">
        <tr>
<td>         
                                    <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged"
                                        Width="200px">
                                    </asp:DropDownList>
                                </td>
</tr>
<tr>
 <td colspan="6" class="tdcontrol">
                <asp:UpdatePanel ID="UpdatePanel6" runat="server">
                    <ContentTemplate>
                        <asp:Panel ID="panelrpt" runat="server" ScrollBars="Auto" Width="100%">
                           
                            <asp:Repeater ID="rptPayment" runat="server" OnItemDataBound="rptPayment_ItemDataBound">
                                <ItemTemplate>
                                    <asp:CheckBox ID="chkComm" runat="server" Checked="true" Text='<%#Eval("CommodityName")%>'
                                        ForeColor="White" Font-Bold="true" />
                                   
                                    <asp:GridView ID="gvPayment" runat="server" AutoGenerateColumns="false" ShowFooter="true"
                                        OnRowDataBound="gvPayment_RowDataBound">
                                        <Columns>
                                            <asp:TemplateField HeaderText="employee" Visible="false">
                                                <ItemTemplate>
                       <asp:Literal  runat="server" Text='<%#Eval("employeeId")%>'></asp:Literal>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                          
                                             
                                           
                                        </Columns>
                                    </asp:GridView>
                                </ItemTemplate>
                            </asp:Repeater>
                        </asp:Panel>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
                    </Triggers>
                </asp:UpdatePanel>
            </td>
  </tr>
<tr>
<td> <asp:UpdatePanel ID="UpdatePanel24" runat="server">
                                <ContentTemplate>
                                    <asp:DropDownList ID="ddlPaymentMode" AutoPostBack="true" runat="server" Width="200px"
                                        OnSelectedIndexChanged="ddlPaymentMode_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </ContentTemplate>
                            </asp:UpdatePanel></td>
</tr>
</table>
Posted
Updated 6-Mar-17 3:13am
Comments
F-ES Sitecore 6-Mar-17 8:58am    
The .net framework has no idea that you have shown or hidden elements via javascript so when the page does a postback it renders it how it thinks it should be shown. If you want to do this you can have a hidden variable on the page and when you hide an element you can also update the hidden variable to something that indicates what has been hidden. On postback your .net code can look at the hidden variable and know something needs shown or hidden server-side. Also bear in mind that if you specify something as Visible=false in server code then it is never sent to the client so you can't show it via js, you'll need to amend the grid to have the appropriate "display" style of block or none instead.
Graeme_Grant 6-Mar-17 9:08am    
what javascript?
F-ES Sitecore 6-Mar-17 9:10am    
hideshowGV
Graeme_Grant 6-Mar-17 10:08am    
true

C#
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
does not call
C#
function hideshowGV(itemId, itemIndex)


If you set break points in code, you will see what is happening. Basic Debugging with Visual Studio 2010 - YouTube[^]
 
Share this answer
 
<asp:UpdatePanel ID="UpdatePanel6" runat="server" UpdateMode="Conditional">


protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
UpdatePanel6.Update();
BindRepeater();
}
 
Share this answer
 

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