Solved

Finding a Panel Inside a Formview Control

Posted on 2010-08-25
10
671 Views
Last Modified: 2013-12-26
Hi,

I have a drop-down list inside a panel control which is inside a form view control. When _SelectedIndexChanged fires, I need the panel to be visible = true when the selected value of the drop-down is = to "Y" so the text box will show.

The vb in the code behind is not working and I can't figure out how to make the _SelectedIndexChanged event work.

This code worked fine until I placed it inside a form view control:

Public Sub ddlRESReturnBalancesCurrentFlg_SelectedIndexChanged(B yVal sender As Object, ByVal e As System.EventArgs) Handles ddlRESReturnBalancesCurrentFlg.SelectedIndexChanged
Dim value As Boolean
If ddlRESReturnBalancesCurrentFlg.SelectedValue = "0" Then
 value = True
Else
 value = False
End If
Me.divRESReturnCurrent2.Visible = value
End Sub

So this is what I have currently:

Markup:


 <asp:FormView ID="fvRtnMasUpdateInfo" runat="server" DataSourceID="dsRtnMasUpdateInfo"
                    AutoGenerateRows="false" DefaultMode="Edit" DataKeyNames="ExecutionStrategyID">
                    <EditItemTemplate>

                <table style="width: 625px;" cellspacing="0" cellpadding="5" border="1" style="margin: 0 auto">
                    <tr>
                        <th style="border-left: solid 1px black; border-right: solid 1px black; border-top: solid 1px black"
                            width="100%" class="H1" colspan="4">
                            <span style="float: left">
                                <asp:ImageButton CommandName="Update" ID="imgUpdate" runat="server" src="../../images/save.png" /></span>
                            <span style="float: none">Return to Master - Notify Client</span>
                        </th>
                    </tr>
                    <tr>
                        <td class="L1" align="right">
                            <asp:Label ID="lblIsLoanCurrent" runat="server" Text="Is Loan Current:" />
                        </td>
                        <td class="D1" align="left">
                            <table>
                                <tr>
                                    <td>


                                         <wc:MacroDropDownList ID="ddlRESReturnCurrentFlg" MacroFieldName="YesNo" AppendDataBoundItems="true"
                                         AddBlankValue="true"  SelectedValue='<%# Bind("RESReturnCurrentFlgX") %>'  ToolTip="RESReturnCurrentFlg" AutoPostBack="true" runat="server">
                                         </wc:MacroDropDownList>
                                       
                                       

                                    </td>
                                     <asp:Panel ID="pnlRESReturnCurrent1" runat="server" Visible="False">
                                    <div id="divRESReturnCurrent1" style="padding-left: 10px;padding-right: 10px;">
                                        <td align="right">
                                            Comment:
                                        </td>
                                        <td align="left">
                                            <asp:TextBox ID="txtRESReturnCurrentNotes" runat="server" Text='<%# Bind("RESReturnCurrentNotes") %>'></asp:TextBox>
                                        </td>
                                    </div>
                                    </asp:Panel>
                                </tr>
                            </table>
                        </td>
                    </tr>
</table>
                </table>
 <br />
                        <span class="requiredRed">* - Required Field</span>
                        <br />
                        <br />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CausesValidation="true"
                            ValidationGroup="EditValidation" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
                    </FooterTemplate>
                </asp:FormView>







Code behind:


Private Sub fvRtnMasUpdateInfo_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles fvRtnMasUpdateInfo.ItemUpdating

        Dim dRRESReturnCurrentFlg As DropDownList = fvRtnMasUpdateInfo.FindControl("ddlRESReturnCurrentFlg")
        Dim dRRESReturnBalancesCurrentFlg As DropDownList = fvRtnMasUpdateInfo.FindControl("ddlRESReturnBalancesCurrentFlg")
        Dim dRRESReturnExpensesPaidFlg As DropDownList = fvRtnMasUpdateInfo.FindControl("ddlRESReturnExpensesPaidFlg")


 If dRRESReturnCurrentFlg.SelectedValue = "Y" Then
            e.NewValues("RESReturnCurrentFlgX") = "Y"
            fvRtnMasUpdateInfo.FindControl("pnlRESReturnCurrent1").Visible = True
        ElseIf dRRESReturnCurrentFlg.SelectedValue = "N" Then
            e.NewValues("RESReturnCurrentFlgX") = "N"
            fvRtnMasUpdateInfo.FindControl("pnlRESReturnCurrent1").Visible = False
        End If

       
End Sub

But nothing happens except the autopostback for the drop-down list fires. The vb above is not being run at all. What am I missing here?

The object is to reveal the text box if the drop-down selection is "Y" either by selecting "Yes" in the drop-down control of on page load if that field contains data that = "Y"

Any help would be appreciated!






0
Comment
Question by:jaysch
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:Rhino1272
Comment Utility
Is the _SelectedIndexChanged event firing at all?
0
 

Author Comment

by:jaysch
Comment Utility
The following code:

Public Sub ddlRESReturnBalancesCurrentFlg_SelectedIndexChanged(B yVal sender As Object, ByVal e As System.EventArgs) Handles ddlRESReturnBalancesCurrentFlg.SelectedIndexChanged
Dim value As Boolean
If ddlRESReturnBalancesCurrentFlg.SelectedValue = "0" Then
 value = True
Else
 value = False
End If
Me.divRESReturnCurrent2.Visible = value
End Sub


Fires OK when not inside a Formview. But I can't figure out how to make it run witha formview.

0
 
LVL 6

Expert Comment

by:Rhino1272
Comment Utility
Is all of this inside an UpdatePanel by any chance?   If so, you might need to add a PostBackTrigger.

       <asp:UpdatePanel id="UpdatePanel1" runat="server" >
        <Triggers>
            <asp:PostBackTrigger ControlID="ddlRESReturnCurrentFlg"/>
        </Triggers>
0
 

Author Comment

by:jaysch
Comment Utility
Interesting. Yes, it's all inside an update panel
0
 
LVL 6

Expert Comment

by:Rhino1272
Comment Utility
So did adding the Trigger work?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:jaysch
Comment Utility
No, unfortunately not. Placed the code in the markup directly under the Update panel tag Error said that the ddl control couldn't be found.
0
 
LVL 6

Expert Comment

by:Rhino1272
Comment Utility
I am trying to recreate your issue.  I will get back with you shortly.
0
 

Author Comment

by:jaysch
Comment Utility
Tnx!
0
 
LVL 6

Accepted Solution

by:
Rhino1272 earned 500 total points
Comment Utility
OK try this:

1) Change your code behind signature from:

Public Sub ddlRESReturnBalancesCurrentFlg_SelectedIndexChanged(B yVal sender As Object, ByVal e As System.EventArgs) Handles ddlRESReturnBalancesCurrentFlg.SelectedIndexChanged

TO

Public Sub ddlRESReturnBalancesCurrentFlg_SelectedIndexChanged(B yVal sender As Object, ByVal e As System.EventArgs)

2) Add this to your dropdownlist declaration:

onselectedindexchanged="ddlRESReturnBalancesCurrentFlg_SelectedIndexChanged"
0
 

Author Closing Comment

by:jaysch
Comment Utility
Rhino172 - That did the trick. Thanks for your help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now