Solved

Finding a Panel Inside a Formview Control

Posted on 2010-08-25
10
678 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
ID: 33521239
Is the _SelectedIndexChanged event firing at all?
0
 

Author Comment

by:jaysch
ID: 33521846
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
ID: 33522047
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

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

Expert Comment

by:Rhino1272
ID: 33522194
So did adding the Trigger work?
0
 

Author Comment

by:jaysch
ID: 33523072
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
ID: 33523372
I am trying to recreate your issue.  I will get back with you shortly.
0
 

Author Comment

by:jaysch
ID: 33523676
Tnx!
0
 
LVL 6

Accepted Solution

by:
Rhino1272 earned 500 total points
ID: 33523715
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
ID: 33538378
Rhino172 - That did the trick. Thanks for your help!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

785 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