• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3711
  • Last Modified:

Accessing FormView controls

Greetings all

I have a formview control with various controls within it (see snippet for SOurec and Page Source)

I am trying to access and set the proPerties of "ddlPortfolioC", a dropdownlist but am coming up with nulls - so obviously I am missing somethign. My code is:

FormView fv = pnlCoupleInfo.FindControl("fvSpousal") as FormView;
Panel pnl = fv.Row.FindControl("pnlActivity") as Panel; <===== ERROR
DropDownList ddl = pnl.FindControl("ddlPortfolioC") as DropDownList;
ddlPortfolioC.DataSourceID = "thePortfolios";
ddlPortfolioC.DataBind();

Any ideas?


In advance, thanks!!

   allanamrk!!
 
SOURCE:
 
 
<%@ Page Language="C#" MasterPageFile="~/MimeMaster01.master" AutoEventWireup="true" CodeFile="People.aspx.cs" Inherits="People" Title="People" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="leftnav" Runat="Server">  
 
    <center>
    <asp:Panel ID="pnlSelOptions" runat="server" GroupingText=" Which records? " Width="200px" 
               Height="65px" CssClass="smallGroupText" HorizontalAlign="Left">
        <asp:CheckBox ID="chkActive" runat="server" Text="Current ME members" Checked="true" CssClass="smallGroupText" AutoPostBack="true" OnCheckedChanged="chkActive_CheckedChanged" />   
        <br />
        <asp:CheckBox ID="chkInvolved" runat="server" Text="Involved in ME" Checked="true" CssClass="smallGroupText" AutoPostBack="true" OnCheckedChanged="chkInvolved_CheckedChanged" />    
    </asp:Panel>    
    <br />
    
    <asp:ListBox ID="lbxCouples" runat="server" CssClass="listbox" AutoPostBack="True">    
    </asp:ListBox>
    <ajaxToolkit:ListSearchExtender ID="ajaxLstCouples" runat="server" TargetControlID="lbxCouples" PromptCssClass="ListSearchExtenderPrompt" ></ajaxToolkit:ListSearchExtender>
    </center>
        
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="rightnav" Runat="Server">
 
   <ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="Server" 
            TargetControlID="pnlSpousalContent"
            ExpandControlID="pnlSpousalTitle" 
            CollapseControlID="pnlSpousalTitle" 
            Collapsed="false"
            TextLabelID="Label1" 
            ExpandedText="(Hide ...)" 
            CollapsedText="(Show ...)"
            ImageControlID="Image1" 
            ExpandedImage="Graphics/collapse.jpg"
            CollapsedImage="~/Graphics/expand.jpg"
            SuppressPostBack="true" AutoExpand="true" >
    </ajaxToolkit:CollapsiblePanelExtender>
        
     <asp:Panel ID="pnlSpousalTitle" runat="server" CssClass="collapsePanelHeader"> 
           <asp:Image ID="Image1" runat="server" ImageUrl="~/Graphics/expand.jpg"/>&nbsp;&nbsp;
           Spousal Details&nbsp;&nbsp;
           <asp:Label ID="Label1" runat="server">(Show Details...)</asp:Label>
    </asp:Panel><br />
    
    <asp:Panel ID="pnlSpousalContent" runat="server" CssClass="collapsePanel">
        <br />
        <asp:Panel ID="pnlCoupleInfo" runat="Server" GroupingText=" Spousal Details ">
        
            <br />
            <asp:FormView ID="fvSpousal" runat="server">                       
                <ItemTemplate>
                    <asp:Label ID="lblCoupleSurnameI" runat="Server" Text="Surname"></asp:Label>
                    <asp:TextBox ID="txtCoupleSurnameI" runat="server" Text=<%# Eval("C_Surname")%> />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="lblMaritalStat" runat="server" Text="Marital Status: "></asp:Label>
                    <asp:DropDownList  ID="ddlMarStatus" runat="server" SelectedValue=<%# Eval("C_Mar_Status") %> >
                       <asp:ListItem Value="M">Married</asp:ListItem>
                       <asp:ListItem Value="D">Divorced</asp:ListItem>
                       <asp:ListItem Value="S">Separated</asp:ListItem>
                       <asp:ListItem Value="W">Widowed</asp:ListItem>
                    </asp:DropDownList>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="txtWedDay" Text=<%# Eval("C_Wed_Anniv") %>" runat="server"></asp:TextBox>
                    <br />
                    <asp:Label ID="lblEmail" runat="Server" Text="Email: "></asp:Label>
                    <asp:TextBox ID="txtEmail" runat="server" Text=<%# Eval("C_Email") %> ></asp:TextBox>
                    <br />
                    <asp:CheckBox ID="chkActive" runat="server" Text="Current in ME" Checked=<%# Eval("C_Active") %> />
                    <br />
                    <asp:Panel ID="pnlActivity" runat="server"  GroupingText=" Committment ">
                        <br />
                        <asp:CheckBox ID="chkInvolved" runat="server" Text="Involved in ME" Checked=<%# Eval("C_Involved_In_ME") %> />
                        <br />
                        <asp:DropDownList  ID="ddlPortfolioC" runat="server" DataTextField="PF_Title"
                         DataValueField="PF_Id" SelectedValue=<%# Eval("C_Portfolio") %>></asp:DropDownList>
                    </asp:Panel>
                    <br />
                    <asp:Label ID="lblComments" runat="Server" Text="Comments: "></asp:Label>
                    <asp:TextBox ID="txtComments" runat="server" Text=<%# Eval("C_Comments") %> TextMode="MultiLine" ></asp:TextBox>
                </ItemTemplate>                                 
            </asp:FormView>    
        <asp:Label ID="test" runat="Server">WHY WHY WHY ???</asp:Label>
        </asp:Panel>
        <!-- ID="pnlCoupleInfo" -->
            
    </asp:Panel>
    <!-- <asp:Panel ID="pnlSpousalContent" >  -->
    <br />
    
    <asp:Panel ID="pnl01" runat="server" BackColor="Lime" Height="75px" Width="98%"></asp:Panel>
    
</asp:Content>
 
 
 
PAGE SOURCE:
 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
 
<head id="ctl00_Head1"><title>
	People
</title><link id="ctl00_cssLink" rel="stylesheet" type="text/css" href="CSS/Mime.CSS" /></head>
 
<body id="ctl00_MasterBody" class="people">
 
<form name="aspnetForm" method="post" action="People.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" style="height: 100%;">
<div>
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMTAwNzA2NTczD2QWAmYPZBYCAgMPFgIeBWNsYXNzBQZwZW9wbGUWAgIBD2QWCmYPDxYCHgRUZXh0BQFQZGQCBg9kFgICAQ9kFgICAQ9kFgJmD2QWAgIBD2QWAgIDDxAPFgYeDURhdGFUZXh0RmllbGQFBE5hbWUeDkRhdGFWYWx1ZUZpZWxkBQVFbWFpbB4LXyFEYXRhQm91bmRnZBAVBxVCcm93biwgTWFyayAmIE1lbGFuaWUTSm9uZXMsIEtlbGx5ICYgUGF1bBRQZXRlcnMsIEJpbGwgJiBXZW5keRdTbWl0aCwgUm9iZXJ0ICYgU2hpcmxleRRUaG9tYXMsIE1lcmxlICYgUGF1bBxWYW4gRGVyIE1lcndlLCBMZXNsZXkgJiBTZWFuFVZhbiBSaWVsLCBBbGxhbiAmIEtpbRUHEGxld2llQG13ZWIuY28uemEQbGV3aWVAbXdlYi5jby56YRBsZXdpZUBtd2ViLmNvLnphEGxld2llQG13ZWIuY28uemEQbGV3aWVAbXdlYi5jby56YRBsZXdpZUBtd2ViLmNvLnphEWF2cmllbEBtd2ViLmNvLnphFCsDB2dnZ2dnZ2cWAWZkAgcPZBYCAgEPZBYCAgMPZBYCZg9kFgICAQ9kFgYCAw8QDxYGHwIFBVRpdGxlHwMFAklkHwRnZBAVBB5Db250YWN0IGRldGFpbHMgZm9yIE1FIG1lbWJlcnMsQ291cGxlIC8gbWVtYmVyIGZvbGxvdy11cHMgdGhhdCBhcmUgb3ZlcmR1ZS4rV2VkZGluZyBhbm5pdmVyc2FyaWVzIHdpdGhpbiBhIHRpbWUgcGVyaW9kLhBQYXJhbWV0ZXJzIHRlc3QuFQQBMQEzATUBNhQrAwRnZ2dnFgFmZAIFD2QWAgIBDw8WAh8BBZEBUHJvdmlkZXMgYW4gaW5kZXB0aCBsaXN0IG9mIGNvbnRhY3QgZGV0YWlscyhhZGRyZXNzLCBwaG9uZSwgZW1haWwpIGZvciBNRSBtZW1iZXJzLiBVU2VyIGlzIGFibGUgdG8gY2hvb3NlIGFjdGl2ZS9pbmFjdGl2ZSBwZXJzb24sIHZpYSBwYXJhbWV0ZXJzLmRkAgsPZBYCAgEPPCsADQBkAgkPZBYCAgMPEA8WBh8CBQROYW1lHwMFAklkHwRnZBAVBRVCcm93biwgTWFyayAmIE1lbGFuaWUTSm9uZXMsIEtlbGx5ICYgUGF1bBdTbWl0aCwgUm9iZXJ0ICYgU2hpcmxleRRUaG9tYXMsIE1lcmxlICYgUGF1bBVWYW4gUmllbCwgQWxsYW4gJiBLaW0VBQE0ATMBNwEyATEUKwMFZ2dnZ2dkZAIKD2QWAgIHD2QWAgIBD2QWAgIBDzwrAAoBAA8WBB8EZx4LXyFJdGVtQ291bnQCAWQWAmYPZBYGZg8PFgIeB1Zpc2libGVoZGQCAQ9kFgJmD2QWBgIHDxAPFgIfBGdkZGRkAggPFQEAZAIPD2QWAgIDDxAPFgIfBGdkZGRkAgIPDxYCHwZoZGQYAwUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgoFEWN0bDAwJGxvZ09uJGN0bDAxBRFjdGwwMCRsb2dPbiRjdGwwMwUeY3RsMDAkbG9nVmlldyRpbWdFTWFpbERpc2FibGVkBR5jdGwwMCRsb2dWaWV3JGltZ1F1ZXJ5RGlzYWJsZWQFGWN0bDAwJE1pbWVRdWVyeSRhY3RpdmVfbWUFHmN0bDAwJE1pbWVRdWVyeSRpbnZvbHZlZF9pbl9tZQUXY3RsMDAkbGVmdG5hdiRjaGtBY3RpdmUFGWN0bDAwJGxlZnRuYXYkY2hrSW52b2x2ZWQFImN0bDAwJHJpZ2h0bmF2JGZ2U3BvdXNhbCRjaGtBY3RpdmUFJGN0bDAwJHJpZ2h0bmF2JGZ2U3BvdXNhbCRjaGtJbnZvbHZlZAUYY3RsMDAkcmlnaHRuYXYkZnZTcG91c2FsDxQrAAdkZGRkZBYAAgFkBRljdGwwMCRNaW1lUXVlcnkkZ3ZSZXN1bHRzD2dkT2Mw308B5xJsYghEA7KN+sOkqXw=" />
 
</div>
 
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
 
 
<script src="/Mime/WebResource.axd?d=w2Oh_XYAlD1kc2UB1iMiRQ2&amp;t=633735699120000000" type="text/javascript"></script>
 
 
<script src="/Mime/ScriptResource.axd?d=J5yVb02xXKXCJH0xCcD25uWPT5pdTLsFbpZgregFRa-gAh20sEccTdprEn05hq6k0JJVEOSQZ-2rh6FLlRNQ2g2&amp;t=633735699120000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=az3Q0esOkYtp1XTOobzJHpK28WHTMypkr1bT257tUjaf0Sfq4080F6XpoeGlS1cToQZs3Xa9w41Nj5PXFictBDXbKmyzxXR62kNZANifsDQ1&amp;t=633655799200000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=az3Q0esOkYtp1XTOobzJHpK28WHTMypkr1bT257tUjaf0Sfq4080F6XpoeGlS1cToQZs3Xa9w41Nj5PXFictBBhOxUm4ZCC8zUmMAY3rn88Y5sL1LoH5mfiFQyjeuhw10&amp;t=633655799200000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBjPEmMHTd8S0YvZmO0J8NCqfl474xUgezUCth4WV2SyQ2&amp;t=633460243600000000" type="text/javascript"></script>
 
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBsA2Rw-e0YWf9G_KrjbNbHwwbiUDwZd72JGvZKXl7WbkAbe8AcLIdNyUqasozG7q81&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBNXvKgWCwQ1QT6M4y60XEL2I8SoS2uH4rMiWUgK1WnkiVpSPXxDUQnU5kUApZOhnZsOV-Mod-Onsq5_JU4T4GC0&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBz4Dxzmr6JEjXwIzwMLmDRK1k0be38VEqbPrqRB93VfA2&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKCPGLlYQ5EuSNNcN4hV8XlJNDXW7wh0KR4Gbvs-Qb8lBA2&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKCPGLlYQ5EuSNNcN4hV8XlJLaxEp6YsQtUffA0gCuhTkPFoCxkPhjRMZpl8XgK5WcM1&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBqQhhLZjKmwrDuHtc_Zp36VPWtzfuSCac3wJbPsJhpRXKMpt8EKFjgj1afu-m8V-A1&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKBA5MMdLWTlguEtpCArVze-DNocHpuFt0j1BSF4wGnxNFqMlN0Ln8K0K_S7-mBR6JI1&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKAoi5MJW_-NIJCZK6NorJO5pxEhjBRpI2zP4wc_mlOKOy7v1U1ZLJQ33aoW5N17cOg1&amp;t=633460243600000000" type="text/javascript"></script>
<script src="/Mime/ScriptResource.axd?d=8FG1YiCJoi_b9yhV_vyzCu6rULxvwrLPC7M9yMWnKKDVh_zSBQCiS-j6CR16KS718-R3PxWFZ3s4P2hO46fCV1Y6BAAiBxao-Mz_DmKqyVLlcf_21ouHYlyEWuwnpwO50&amp;t=633460243600000000" type="text/javascript"></script>
 
<script src="/Mime/WebResource.axd?d=8hZjR3SPlLMlsK9cUb8Nag2&amp;t=633735699120000000" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
 
<div>
 
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWMAKVq4SpBgLMsaewDALO2JHVBAKFn/xRAorZ2cQNApuDjtgBApuDjtgBApuDjtgBApuDjtgBApuDjtgBApuDjtgBAqPptPoJAtzlx4IHAvuUvFMCocSixgcCmPWb2AsCp8zmzggC8ujN1g0C/YfnuAEC/4fnuAEC+YfnuAEC+IfnuAECoN+Z1AwC0eaJ5QoC+anrrAUCwdXTnAcC0aO9uAUCnp+Stw8Cq5SRrQoCkeaf6QkC7vrfnQwC4pX1cwLjlfVzAueV9XMC4JX1cwLhlfVzAtK+q78MAr+Kjc4CAqCV8IsJAozh0bwFArPh0bwFAoLh0bwFAobh0bwFAtuFm94CAoH/oLICAvSU4YQFAv6c9aICAvvVr7cOw2bw/Gl8pES/Tga7XOjdkOp0LMw=" />
</div>
    
<div id="container" >
  
    <a name="theTop" ></a>  
    
	<div id="header">
	<!-- Header start -->		  
                          		  
		<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$scriptmanager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00$ucEmailer$UpdatePanel1','tctl00$MimeQuery$uppnlQuery'], [], [], 90);
//]]>
 
</script>
          
         
        
           
        <br />           
        <a id="ctl00_logOn" class="loginStat" href="javascript:__doPostBack('ctl00$logOn$ctl02','')">Login</a>              
         
        <center>
		<h1>Marriage Encounter - Western Cape</h1>
		<h5>(Administration Management)</h5>
        </center>      
 
        <img id="ctl00_headerPict" class="headerPic" src="Graphics/ME05.Gif" style="border-width:0px;z-index: 100" />
 
        <div style="float:right; top:10px">
 
           
                <input type="image" name="ctl00$logView$imgEMailDisabled" id="ctl00_logView_imgEMailDisabled" disabled="disabled" src="Graphics/EMail05.jpg" style="border-width:0px;" />
                    &nbsp;&nbsp;&nbsp 
                <input type="image" name="ctl00$logView$imgQueryDisabled" id="ctl00_logView_imgQueryDisabled" disabled="disabled" src="Graphics/Query01.jpg" style="border-width:0px;" /> 
             
        </div>
 
 
        <center>
        <ul id='menu' style="width: 63%">
              <li ><a href='/Mime/Default.aspx'  id='menuHome' >Home</a></li>
              <li ><a href='/Mime/People.aspx' id='menuPeople' >People</a></li>
 
              <li ><a href='/Mime/Default2.aspx' id='menuCircles' >Circles</a></li>
              <li ><a href='/Mime/Default2.aspx' id='menuWeekends' >Weekends</a></li>
              <li ><a href='/Mime/Default2.aspx' id='menuEvents' >Events</a></li>
              <li ><a href='/Mime/Default2.aspx' id='menuGeneral' >General</a></li>
              <li ><a href='/Mime/Default2.aspx' id='menuPortfolios' >Portfolio</a></li>
              <li ><a href='/Mime/Default2.aspx' id='menuUsers' >Users</a></li>
 
        </ul>
        </center>
        
        <div style="height:15px"></div>
            
        <hr  width="96%" class="redline"/>
          
	<!-- Header end -->
	</div>
	
	<div id="body">
    <!-- Body start -->
    <div id="ctl00_pnlHolderEmail" class="modalPopup" style="width:620px;display: none">
 
	
        
 
<script type ="text/javascript" language="javascript">
 
 function ClearTheIt()
{
   document.getElementById('ctl00_ucEmailer_txtSubject').value = '';
   document.getElementById('ctl00_ucEmailer_txtMessage').value = '';   
   var control = document.getElementById('ctl00_ucEmailer_txtSubject');
   if( control != null ){ control.focus(); }
   return false;
}
 
</script>      
 
 
 
<div id="ctl00_ucEmailer_UpdatePanel1">
		
    <div id="ctl00_ucEmailer_pnlMail" style="width:600px;">
			   
    <br />
    
    <table id="email" style="position: relative" >
 
       <!-- To -->
       <tr>
            <td style="width: 75px">
 
                <span id="ctl00_ucEmailer_lblTo" class="smallerFontSize">To:</span>
                </td>
                <td colspan="2">
                <select name="ctl00$ucEmailer$ddlAddresses" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ucEmailer$ddlAddresses\',\'\')', 0)" id="ctl00_ucEmailer_ddlAddresses" style="width:325px;">
				<option selected="selected" value="lewie@mweb.co.za">Brown, Mark &amp; Melanie</option>
				<option value="lewie@mweb.co.za">Jones, Kelly &amp; Paul</option>
 
				<option value="lewie@mweb.co.za">Peters, Bill &amp; Wendy</option>
				<option value="lewie@mweb.co.za">Smith, Robert &amp; Shirley</option>
				<option value="lewie@mweb.co.za">Thomas, Merle &amp; Paul</option>
				<option value="lewie@mweb.co.za">Van Der Merwe, Lesley &amp; Sean</option>
 
				<option value="avriel@mweb.co.za">Van Riel, Allan &amp; Kim</option>
 
			</select>                
            </td>
       </tr>      
       
        <tr>                
        <!-- Row: Blank  -->
            <td colspan="2" height="12"></td>
        </tr>
 
 
       <!-- Row: Subject -->
       <tr>                
            <td style="width: 75px">
		        <label for="ctl00_ucEmailer_txtSubject" id="ctl00_ucEmailer_lblSubject" class="smallerFontSize" style="width:175px;">Subject:</label>
            </td>
            <td colspan="2">
                <input name="ctl00$ucEmailer$txtSubject" type="text" id="ctl00_ucEmailer_txtSubject" style="width:350px;" />
	    	    <span id="ctl00_ucEmailer_rfvSubject" class="smallFontSize" style="color:Red;position:relative;visibility:hidden;">Required Field</span></td>            
    	<!-- End: Row: Subject -->
 
        </tr>
 
        <tr>                
        <!-- Row: Blank  -->
            <td colspan="2" height="12"></td>
        </tr>
            
        <tr>                
        <!-- Row: Message -->
            <td style="width: 75px">
    		    <label for="ctl00_ucEmailer_txtMessage" id="ctl00_ucEmailer_lblMessage" class="smallerFontSize">Message:</label>
 
            </td>
            <td colspan="2">
		        <textarea name="ctl00$ucEmailer$txtMessage" rows="2" cols="20" id="ctl00_ucEmailer_txtMessage" style="height:200px;width:475px;"></textarea>
		        <span id="ctl00_ucEmailer_rfvMessage" class="smallFontSize" style="color:Red;position:relative;visibility:hidden;">Required Field</span>        
            </td>            
	    <!-- End: Row: Message -->
        </tr>
 
        <tr>                
	    <!-- Row: Blank  -->
 
            <td colspan="2" height="1"></td>
        </tr>
              
    <!-- End: table id="email". -->
    </table>     
    
   <center>
    <input type="submit" name="ctl00$ucEmailer$btnSendTheEMail" value="Send" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ucEmailer$btnSendTheEMail&quot;, &quot;&quot;, true, &quot;SendEmail&quot;, &quot;&quot;, false, false))" id="ctl00_ucEmailer_btnSendTheEMail" class="buttons" />  
    &nbsp;&nbsp;&nbsp;
    <input type="submit" name="ctl00$ucEmailer$btnClear" value="Clear" onclick="return ClearIt();" id="ctl00_ucEmailer_btnClear" class="buttons" />        
    </center><br />
 
    
		</div>
 
    <!-- <asp:Panel ID=pnlMail"> -->
 
	</div>
 
            
        <center>
        <input type="submit" name="ctl00$btnCloseEmail" value="Close" id="ctl00_btnCloseEmail" class="buttons" />
        </center>
    
</div>
    <div id="ctl00_pnlHolderQuery" class="modalPopup" style="width:710px;display: none">
	
        
 
 
    <style type="text/css">
        .WrapperDiv {
            width:325px;height:200px;border: 1px solid black;
        }        
        .WrapperDiv TH {
            position:relative;
        }
        .WrapperDiv TR 
        {
	        /* Needed for IE */
            height:0px;
        } 
        
        .SmallerFont
        {
        font-size:small;
        }
    </style>
 
    
    <script type ="text/javascript" language="javascript">
        function onLoad()
        {
            FreezeGridViewHeader('gvResults','WrapperDiv');
        }    
        
        
        function FreezeGridViewHeader(gridID,wrapperDivCssClass) 
        {
            /// <summary>
            ///   Used to create a fixed GridView header and allow scrolling
            /// </summary>
            /// <param name="gridID" type="String">
            ///   Client-side ID of the GridView control
            /// </param>
            /// <param name="wrapperDivCssClass" type="String">
            ///   CSS class to be applied to the GridView's wrapper div element.  
            ///   Class MUST specify the CSS height and width properties.  
            ///   Example: width:800px;height:400px;border:1px solid black;
            /// </param>
            var grid = document.getElementById(gridID);
            if (grid != 'undefined')
            {
                grid.style.visibility = 'hidden';
                var div = null;
                if (grid.parentNode != 'undefined') 
                {
                    //Find wrapper div output by GridView
                    div = grid.parentNode;
                    if (div.tagName == "DIV")
                    {
                        div.className = wrapperDivCssClass;  
                        div.style.overflow = "auto";                   
                    }
                }                
                //Find DOM TBODY element and remove first TR tag from 
                //it and add to a THEAD element instead so CSS styles
                //can be applied properly in both IE and FireFox
                var tags = grid.getElementsByTagName('TBODY');
                if (tags != 'undefined')
                {
                    var tbody = tags[0];
                    var trs = tbody.getElementsByTagName('TR');
                    var headerHeight = 8;
                    if (trs != 'undefined') 
                    {
                        headerHeight += trs[0].offsetHeight;
                        var headTR = tbody.removeChild(trs[0]);
                        var head = document.createElement('THEAD');
                        head.appendChild(headTR);
                        grid.insertBefore(head, grid.firstChild);
                    }
                    //Needed for Firefox
                    tbody.style.height = 
                      (div.offsetHeight -  headerHeight) + 'px';
                    tbody.style.overflowX = "hidden";
                    tbody.overflow = 'auto';
                    tbody.overflowX = 'hidden';
                }
                grid.style.visibility = 'visible';
            }
        }
    </script>
 
 
&nbsp;&nbsp;
 
<div id="ctl00_MimeQuery_uppnlQuery">
		
 
<div id="ctl00_MimeQuery_pnlQuery" class="groupText" style="width:700px;">
			      
    <br />
    <center>
    <label for="ctl00_MimeQuery_ddlQueries" id="ctl00_MimeQuery_lblAvailable" class="smallFontSize">Available</label>
 
    <select name="ctl00$MimeQuery$ddlQueries" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MimeQuery$ddlQueries\',\'\')', 0)" id="ctl00_MimeQuery_ddlQueries" style="width:400px;">
				<option selected="selected" value="1">Contact details for ME members</option>
				<option value="3">Couple / member follow-ups that are overdue.</option>
				<option value="5">Wedding anniversaries within a time period.</option>
				<option value="6">Parameters test.</option>
 
			</select>
 
    </center>
    
    <div id="ctl00_MimeQuery_pnlDesc" class="smallGroupText">
				<fieldset>
					<legend>
						 Description 
					</legend>    
        <textarea name="ctl00$MimeQuery$txtDesc" rows="2" cols="20" id="ctl00_MimeQuery_txtDesc" disabled="disabled" class="smallFontSize" style="width:675px;">Provides an indepth list of contact details(address, phone, email) for ME members. USer is able to choose active/inactive person, via parameters.</textarea>
    
				</fieldset>
			</div>
 
        
    <div id="ctl00_MimeQuery_pnlParameters" class="smallGroupText">
				<fieldset>
					<legend>
						 Parameters 
					</legend>        
        <span id="ctl00_MimeQuery_lbl1" style="display:inline-block;font-size:Smaller;width:225px;">Only those listed as belonging to ME</span><input id="ctl00_MimeQuery_active_me" type="checkbox" name="ctl00$MimeQuery$active_me" checked="checked" /><br><span id="ctl00_MimeQuery_lbl2" style="display:inline-block;font-size:Smaller;width:225px;">Only those actively involved in ME</span><input id="ctl00_MimeQuery_involved_in_me" type="checkbox" name="ctl00$MimeQuery$involved_in_me" checked="checked" /><br>
    
				</fieldset>
			</div>
    
    <div  style="height: 5px;"></div>
 
    
    <center>
    <input type="submit" name="ctl00$MimeQuery$btnExecute" value="Execute Query" id="ctl00_MimeQuery_btnExecute" class="buttons" />
    </center>
 
    <div  style="height:5px;"></div>
    
    <center><hr width="75%" class="redline" /></center>
    
    <div  style="height:5px;"></div>
        
        <center>
        <div id="ctl00_MimeQuery_sPanel" style="background-color:Pink;height:160px;width:92%;overflow-x:scroll;">
 
				
            <div>
 
				</div>
        
			</div>
        </center>
 
    <div  style="height:10px;"></div>    
    
    <center>
        &nbsp;
        &nbsp;<input type="submit" name="ctl00$MimeQuery$btnSaveResults" value="Save Results" id="ctl00_MimeQuery_btnSaveResults" disabled="disabled" class="buttons" />
 
    </center>    
    <br />
 
		</div>
<!-- <asp:Panel ID=pnlQuery"> -->
 
 
	</div>
        
        <center>
        <input type="submit" name="ctl00$btnCloseQuery" value="Close" id="ctl00_btnCloseQuery" class="buttons" />
        </center>
 
    
</div>
    
	<div id="dummy" style="position:relative; height: 40px"></div>
	        
	 
        <div id="wrapperDiv" class="wrapper"> 	
	  
	    <div id="left" class="leftnav">	
               
                <br />
	             
		       
		      
 
    <center>
    <div id="ctl00_leftnav_pnlSelOptions" class="smallGroupText" style="height:65px;width:200px;text-align:left;">
	<fieldset>
		<legend>
			 Which records? 
		</legend>
 
        <span class="smallGroupText"><input id="ctl00_leftnav_chkActive" type="checkbox" name="ctl00$leftnav$chkActive" checked="checked" onclick="javascript:setTimeout('__doPostBack(\'ctl00$leftnav$chkActive\',\'\')', 0)" /><label for="ctl00_leftnav_chkActive">Current ME members</label></span>   
        <br />
        <span class="smallGroupText"><input id="ctl00_leftnav_chkInvolved" type="checkbox" name="ctl00$leftnav$chkInvolved" checked="checked" onclick="javascript:setTimeout('__doPostBack(\'ctl00$leftnav$chkInvolved\',\'\')', 0)" /><label for="ctl00_leftnav_chkInvolved">Involved in ME</label></span>    
    
	</fieldset>
</div>    
    <br />
    
    <select size="4" name="ctl00$leftnav$lbxCouples" onchange="javascript:setTimeout('__doPostBack(\'ctl00$leftnav$lbxCouples\',\'\')', 0)" id="ctl00_leftnav_lbxCouples" class="listbox">
	<option selected="selected" value="4">Brown, Mark &amp; Melanie</option>
 
	<option value="3">Jones, Kelly &amp; Paul</option>
	<option value="7">Smith, Robert &amp; Shirley</option>
	<option value="2">Thomas, Merle &amp; Paul</option>
	<option value="1">Van Riel, Allan &amp; Kim</option>
 
</select>
    <input type="hidden" name="ctl00$leftnav$ajaxLstCouples_ClientState" id="ctl00_leftnav_ajaxLstCouples_ClientState" />
    </center>
        
 
            
        </div>
        
        <div id="right" class="rightnav">	
              
 
   <input type="hidden" name="ctl00$rightnav$cpe_ClientState" id="ctl00_rightnav_cpe_ClientState" />
     <span id="ctl00_rightnav_Allan"></span>   
     <div id="ctl00_rightnav_pnlSpousalTitle" class="collapsePanelHeader">
	 
           <img id="ctl00_rightnav_Image1" src="Graphics/expand.jpg" style="border-width:0px;" />&nbsp;&nbsp;
           Spousal Details&nbsp;&nbsp;
 
           <span id="ctl00_rightnav_Label1">(Show Details...)</span>
    
</div><br />
    
    <div id="ctl00_rightnav_pnlSpousalContent" class="collapsePanel">
	
        <br />
        <div id="ctl00_rightnav_pnlCoupleInfo">
		<fieldset>
			<legend>
				 Spousal Details 
			</legend>        
            <br />
 
            <table cellspacing="0" border="0" id="ctl00_rightnav_fvSpousal" style="border-collapse:collapse;">
				<tr>
					<td colspan="2">
                    <span id="ctl00_rightnav_fvSpousal_lblCoupleSurnameI">Surname</span>
                    <input name="ctl00$rightnav$fvSpousal$txtCoupleSurnameI" type="text" value="Brown" id="ctl00_rightnav_fvSpousal_txtCoupleSurnameI" />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <span id="ctl00_rightnav_fvSpousal_lblMaritalStat">Marital Status: </span>
                    <select name="ctl00$rightnav$fvSpousal$ddlMarStatus" id="ctl00_rightnav_fvSpousal_ddlMarStatus">
 
						<option selected="selected" value="M">Married</option>
						<option value="D">Divorced</option>
						<option value="S">Separated</option>
						<option value="W">Widowed</option>
 
					</select>
                    &nbsp;&nbsp;&nbsp;&nbsp;
 
                    <asp:TextBox ID="txtWedDay" Text=" runat="server"></asp:TextBox>
                    <br />
                    <span id="ctl00_rightnav_fvSpousal_lblEmail">Email: </span>
                    <input name="ctl00$rightnav$fvSpousal$txtEmail" type="text" value="lewie@mweb.co.za" id="ctl00_rightnav_fvSpousal_txtEmail" />
                    <br />
                    <input id="ctl00_rightnav_fvSpousal_chkActive" type="checkbox" name="ctl00$rightnav$fvSpousal$chkActive" checked="checked" /><label for="ctl00_rightnav_fvSpousal_chkActive">Current in ME</label>
                    <br />
                    <div id="ctl00_rightnav_fvSpousal_pnlActivity">
 
						<fieldset>
							<legend>
								 Committment 
							</legend>
                        <br />
                        <input id="ctl00_rightnav_fvSpousal_chkInvolved" type="checkbox" name="ctl00$rightnav$fvSpousal$chkInvolved" checked="checked" /><label for="ctl00_rightnav_fvSpousal_chkInvolved">Involved in ME</label>
                        <br />
                        <select name="ctl00$rightnav$fvSpousal$ddlPortfolioC" id="ctl00_rightnav_fvSpousal_ddlPortfolioC">
								<option selected="selected" value="">-- Not set --</option>
 
							</select>
                    
						</fieldset>
					</div>
                    <br />
                    <span id="ctl00_rightnav_fvSpousal_lblComments">Comments: </span>
                    <textarea name="ctl00$rightnav$fvSpousal$txtComments" rows="2" cols="20" id="ctl00_rightnav_fvSpousal_txtComments"></textarea>
                </td>
 
				</tr>
			</table>    
            <span id="ctl00_rightnav_test">WHY WHY WHY ???</span>
        
		</fieldset>
	</div>
        <!-- ID="pnlCoupleInfo" -->
            
    
</div>
    <!-- <asp:Panel ID="pnlSpousalContent" >  -->
    <br />
 
    
    <div id="ctl00_rightnav_pnl01" style="background-color:Lime;height:75px;width:98%;">
 
</div>
    
 
        </div>
      
      <!-- <div id="wrapper"> 	 -->
      </div>
        
        <!-- Give a little space -->
        <div style="height:45px"></div>
        
    <!-- Body end -->
	</div>
 
	
	<div id="footer">
	<!-- Footer start -->
	
		  <center><hr width="75%" class="redline" /></center>
		  
		  <!-- Give a little space -->
          <div style="height:10px"></div>
		  
		  <center><a href="#theTop" class="anchor"  >Back to top</a></center>
		  
		  <br />
          <center>Marriage Encounter Western Cape &reg; is a registered trademark of Marriage Encounter Western Cape, Inc<br />
 
          &copy; 2009 Marriage Encounter Western Cape, Inc.
          </center>            
        
	<!-- Footer end -->
	</div>    
 
<!-- Div: "Container"  end -->
</div>
 
 
<script type="text/javascript">
//<![CDATA[
var Page_Validators =  new Array(document.getElementById("ctl00_ucEmailer_rfvSubject"), document.getElementById("ctl00_ucEmailer_rfvMessage"));
//]]>
</script>
 
<script type="text/javascript">
//<![CDATA[
var ctl00_ucEmailer_rfvSubject = document.all ? document.all["ctl00_ucEmailer_rfvSubject"] : document.getElementById("ctl00_ucEmailer_rfvSubject");
ctl00_ucEmailer_rfvSubject.controltovalidate = "ctl00_ucEmailer_txtSubject";
ctl00_ucEmailer_rfvSubject.focusOnError = "t";
ctl00_ucEmailer_rfvSubject.errormessage = "Required Field";
ctl00_ucEmailer_rfvSubject.validationGroup = "SendEmail";
ctl00_ucEmailer_rfvSubject.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_ucEmailer_rfvSubject.initialvalue = "";
var ctl00_ucEmailer_rfvMessage = document.all ? document.all["ctl00_ucEmailer_rfvMessage"] : document.getElementById("ctl00_ucEmailer_rfvMessage");
ctl00_ucEmailer_rfvMessage.controltovalidate = "ctl00_ucEmailer_txtMessage";
ctl00_ucEmailer_rfvMessage.focusOnError = "t";
ctl00_ucEmailer_rfvMessage.errormessage = "Required Field";
ctl00_ucEmailer_rfvMessage.validationGroup = "SendEmail";
ctl00_ucEmailer_rfvMessage.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_ucEmailer_rfvMessage.initialvalue = "";
//]]>
</script>
 
<script type="text/javascript">
//<![CDATA[
 
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
    ValidatorOnLoad();
}
 
function ValidatorOnSubmit() {
    if (Page_ValidationActive) {
        return ValidatorCommonOnSubmit();
    }
    else {
        return true;
    }
}
        WebForm_AutoFocus('ctl00_ucEmailer_txtSubject');Sys.Application.initialize();
 
document.getElementById('ctl00_ucEmailer_rfvSubject').dispose = function() {
    Array.remove(Page_Validators, document.getElementById('ctl00_ucEmailer_rfvSubject'));
}
 
document.getElementById('ctl00_ucEmailer_rfvMessage').dispose = function() {
    Array.remove(Page_Validators, document.getElementById('ctl00_ucEmailer_rfvMessage'));
}
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.ListSearchBehavior, {"ClientStateFieldID":"ctl00_leftnav_ajaxLstCouples_ClientState","id":"ctl00_leftnav_ajaxLstCouples","promptCssClass":"ListSearchExtenderPrompt"}, null, null, $get("ctl00_leftnav_lbxCouples"));
});
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.CollapsiblePanelBehavior, {"AutoExpand":true,"ClientStateFieldID":"ctl00_rightnav_cpe_ClientState","CollapseControlID":"ctl00_rightnav_pnlSpousalTitle","CollapsedImage":"Graphics/expand.jpg","CollapsedText":"(Show ...)","ExpandControlID":"ctl00_rightnav_pnlSpousalTitle","ExpandedImage":"Graphics/collapse.jpg","ExpandedText":"(Hide ...)","ImageControlID":"ctl00_rightnav_Image1","SuppressPostBack":true,"TextLabelID":"ctl00_rightnav_Label1","id":"ctl00_rightnav_cpe"}, null, null, $get("ctl00_rightnav_pnlSpousalContent"));
});
//]]>
</script>
</form>
 
</body>
 
</html>

Open in new window

0
allanmark
Asked:
allanmark
  • 7
  • 4
4 Solutions
 
NazoUKCommented:
A couple of thoughts:
1. I don't think it's necessary to call FindControl on FormView.Row whenever I've done it I've just used FormView.FindControl directly.

2. If the formview isn't in the correct mode or doesn't have data then Findcontrol will fail. In other words, at the point you are calling it, the FormView should already be populated with a valid datarecord, otherwise no controls will have been created and there will be nothing to find.
0
 
allanmarkAuthor Commented:
Maybe I'm missing the boat  .......

I am trying to bind the DropDown,  "ddlPortfolioC", to a DataTable which is created at runtime, hence the binding is only done then (ddlPortfolioC.DataSourceID = "thePortfolios";  and ddlPortfolioC.DataBind();).

Both the DropDown and the panel within which it is (pnlActivity) can be seen in the source, so they have been created.

Once the DropDown is bound, the next step is the binding of the FormView (unless I''ve go it wrong and this should happen before the binding of the DropDown)

A few other thoughts ....

1.  I am using a MasterPage
2.  The panel within which DropDown, "ddlPortfolioC" is contained is, itself, contained within the
    ItemTemplate
0
 
NazoUKCommented:
The ChildControls of the FormView aren't created until Data is Bound to it so you can't bind data to the dropdownlist before the FormView itself.

Probably the easiest thing to do would be to put the code to bind the dropdownlist inside the DataBound event of the formview, then you know the controls will be created (assuming a valid data record). You'd probably have to set the dropdownlist selectedvalue manually using this method.

Also I didn't pick up on this before but panel does not implement INamingContainer, thus you don't need to search the panel for controls nested within it.

So FormView fv = pnlCoupleInfo.FindControl("fvSpousal") as FormView; isn't necessary. You can access fvSpousal directly. I think you should find your dropdownlist in the FormView itself rather than the containing panel.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
allanmarkAuthor Commented:
Thanks!

I cleared the DataField, SelectedValue fields form the source.

Then I created the DataBound event (attached) and attempted to create a DropDown control by finding "ddlcPortFolioC". " I placed a break at the end and checked "ddl" - it is null.

The rest of the forview is fine. The formview databinding is working and I am seeing the expected values. It;'s just this one dropdown!
SOURCE:
 
            <asp:FormView  ID="fvSpousal" runat="server" DefaultMode="ReadOnly" OnDataBound="fvSpousal_DataBound">                       
 
<asp:DropDownList  ID="ddlPortfolioC" runat="server"  AppendDataBoundItems="true">
                        <asp:ListItem Text="-- Not set --" Value="" />
                        </asp:DropDownList>
 
 
CODE BEHIND:
 
protected void fvSpousal_DataBound(object sender, EventArgs e)
    {
 
//Note: None of these 3 ways worked!
        DropDownList ddl = (DropDownList)fvSpousal.Row.FindControl("ddlcPortfolioC");
// This didn't work:
//   DropDownList ddl = //(DropDownList)fvSpousal.FindControl("ddlcPortfolioC");
// This didn't work:
DropDownList ddl = (DropDownList)fvSpousal.Row.FindControl("ctl00_rightnav_fvSpousal_ddlPortfolioC");
 
      //  ddlPortfolioC.DataSource = "dtThePortfolios";
      //  ddlPortfolioC.DataBind();
 
    }

Open in new window

0
 
NazoUKCommented:
I'm puzzled why this approach isn't working. I knocked up something that vaguely resembles your structure and it works fine (see snippet). Perhaps it will help you to track down where things aren't working.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="fvSpousal" runat="server" OnDataBound="fv_DataBound">                       
            <ItemTemplate>                
                <asp:Panel ID="pnlActivity" runat="server"  GroupingText=" Committment ">                    
                    <br />
                    <asp:DropDownList  ID="ddlPortfolioC" runat="server" DataTextField="PF_Title"
                     DataValueField="PF_Id"></asp:DropDownList>
                </asp:Panel>
                <br />
                <asp:Label ID="lblComments" runat="Server" Text="Comments: "></asp:Label>
                <asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" ></asp:TextBox>
            </ItemTemplate>                                 
        </asp:FormView>   
    </div>
    </form>
</body>
</html>
 
using System;
using System.Collections;
using System.Web.UI;
 
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //add some dummy data so binding will work...
        fvSpousal.DataSource = new ArrayList{"Hello"};
        fvSpousal.DataBind();
    }
 
    protected void fv_DataBound(object sender, EventArgs e)
    {
        Control c = fvSpousal.FindControl("ddlPortfolioC");
    }
}

Open in new window

0
 
allanmarkAuthor Commented:
Tks!  We are nearly there!

"Control ddl = fvSpousal.FindControl("ddlPortfolioC");"  finds the Control but no DataSource proeprties are available.

Instead of this: "DropDownList ddl = (DropDownList)fvSpousal.Row.FindControl..." I tried this: "DropDownList ddl2 = fvSpousal.FindControl("ddlPortfolioC") as DropDownList;".

This gives a DropDown control with the DataSource properties!!!.

Execution now starts, but falls over with "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." on the SelectedValue in the DropDown.

 <asp:DropDownList  ID="ddlPortfolioC" runat="server"   SelectedValue=<%# Eval("C_Portfolio") %> AppendDataBoundItems="true">
                        <asp:ListItem Text="-- Not set --" Value="" />
                        </asp:DropDownList>
 
protected void fvSpousal_DataBound(object sender, EventArgs e)
    {        
        Control ddl = fvSpousal.FindControl("ddlPortfolioC");
        DropDownList ddl2 = fvSpousal.FindControl("ddlPortfolioC") as DropDownList;
 
        ddl2.DataSource = "dtThePortfolios";
        ddl2.DataTextField="PF_Title";
        ddl2.DataValueField = "PF_Id";
        ddl2.DataBind();
    }

Open in new window

0
 
NazoUKCommented:
Yeah, as I said you'll have to set the DropDown SelectedValue manually. Take off the SelectedValue=<%#Eval... part then inside the databound routine add code to get the required value and set the selected value.

The FormView has a DataItem property that contains the data for the displayed item. Depending on what format the data is you've bound to it you'll have to cast it to the correct type and then get out the value of C_Portfolio from it.
If the data is a custom business object, cast it to that, if it's a stored procedure result it will depend on how you've returned the data.
If you're not sure just put something like object o = fvSpousal.DataItem; then set a breakpoint and hover the mouse, Visual Studio will tell you the correct type to use.
0
 
allanmarkAuthor Commented:
Thank you! Looks like it's there!

Coffee break and then I'll do a proper test. Will postback as soon a sthat's done.
SOURCE:
 
<asp:DropDownList  ID="ddlPortfolioC" runat="server"  AppendDataBoundItems="true">
                        <asp:ListItem Text="-- Not set --" Value="" />
                        </asp:DropDownList>
 
 
CODE BEHIND:
 
protected void fvSpousal_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl2 = fvSpousal.FindControl("ddlPortfolioC") as DropDownList;
 
        ddl2.DataSource = dtThePortfolios;
        ddl2.DataTextField = "PF_Title";
        ddl2.DataValueField = "PF_Id";
        ddl2.DataBind();
      
        DataRowView drv = (DataRowView)fvSpousal.DataItem;
        ddl2.SelectedValue = drv["C_Portfolio"].ToString();
    }

Open in new window

0
 
allanmarkAuthor Commented:
Yip!

It's working.

Now all I need to do is figure out:

1.  Why the date (C_Wed_Anniv" is ignoring the formattign attached to tthe "Eval"  ?
2. Why the ItemTemplate is allowing me to change fields?
    <asp:Panel ID="pnlSpousalContent" runat="server" CssClass="collapsePanel">        
        <br />
        <asp:Panel ID="pnlCoupleInfo" runat="Server" GroupingText=" Spousal Details " CssClass="smallFontSize">        
            <br />
            <asp:FormView  ID="fvSpousal" runat="server" DefaultMode="ReadOnly" OnDataBound="fvSpousal_DataBound">                       
                <ItemTemplate>
                    <asp:Label ID="lblCoupleSurnameI" runat="Server" Text="Surname:"></asp:Label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="txtCoupleSurnameI" runat="server" Text=<%# Eval("C_Surname")%> />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="lblMaritalStat" runat="server" Text="Marital Status: "></asp:Label>
                    <asp:DropDownList  ID="ddlMarStatus" runat="server" SelectedValue=<%# Eval("C_Mar_Status") %> >
                       <asp:ListItem Value="M">Married</asp:ListItem>
                       <asp:ListItem Value="D">Divorced</asp:ListItem>
                       <asp:ListItem Value="S">Separated</asp:ListItem>
                       <asp:ListItem Value="W">Widowed</asp:ListItem>
                    </asp:DropDownList>     
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="lblWed" runat="Server" Text="Wedding date:"></asp:Label>&nbsp;&nbsp;               
                    
                    <asp:TextBox ID="txtWedDay" Text=<%# Eval("C_Wed_Anniv", "{0:yyyy/MM/dd}") %>" runat="server"></asp:TextBox> 
                    <div style="height:5px;"></div>
                    <asp:Label ID="lblEmail" runat="Server" Text="Email: "></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="txtEmail" runat="server" Text=<%# Eval("C_Email") %>  Width="375px"></asp:TextBox>
                    <div style="height:3px;"></div>
                    <asp:CheckBox ID="chkActive" runat="server" TextAlign="Left" Text="Current in ME&nbsp;&nbsp;" Checked=<%# Eval("C_Active") %> />
                    <br />
                    <asp:Panel ID="pnlActivity" runat="server"  GroupingText=" Committment ">
                        <div style="height:1px;"></div>
                        <asp:CheckBox ID="chkInvolved" runat="server" TextAlign="Left" Text="Involved in ME&nbsp;&nbsp;" Checked=<%# Eval("C_Involved_In_ME") %> />
                        <div style="height:3px;"></div>
                        <asp:DropDownList  ID="ddlPortfolioC" runat="server"  AppendDataBoundItems="true">
                        <asp:ListItem Text="--- None ---" Value="" />
                        </asp:DropDownList>
                    </asp:Panel>
                    <div style="height:5px;"></div>
                    <asp:Label ID="lblComments" runat="Server" Text="Comments: "></asp:Label>
                    <br />
                    <asp:TextBox ID="txtComments" runat="server" Text=<%# Eval("C_Comments") %> TextMode="MultiLine" Width="650px" ></asp:TextBox>
                    <div style="height:5px;"></div>
                </ItemTemplate>                                 
            </asp:FormView>    
        </asp:Panel>
        <!-- ID="pnlCoupleInfo" -->
            
    </asp:Panel>
    <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 494px; position: absolute;
        top: 96px"></asp:TextBox>
    <!-- <asp:Panel ID="pnlSpousalContent" >  -->
    <br />
    
    <asp:Panel ID="pnl01" runat="server" BackColor="Lime" Height="75px" Width="98%"></asp:Panel>

Open in new window

0
 
allanmarkAuthor Commented:
Silly me!!  -  I was using Textboxes and not disabling them!!
0
 
allanmarkAuthor Commented:
Many thanks for the excellent supprot and patience!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now