Can't visible property of DropDownList in FormView control

Discussion in 'ASP .Net Web Controls' started by Hollywood, Feb 7, 2008.

  1. Hollywood

    Hollywood Guest

    I have a formview control that contains a dropdownlist (nested in a
    panel) and I want to set the visible property to False when the user
    is in a particular role. I'm using a modal popup button click event
    to fire the change, and I set the formview mode to Insert and that
    works great. Just after that I try to set the dropdownlist.visible =
    false (or true depending) and I can find the control okay but it never
    sets the visibility.

    I've been chasing after this for a couple of days and any help would
    really be appreciated!! :)



    Here's the code:

    aspx page:

    <asp:FormView ID="FormView1" runat="server" DataSourceID="Dealer"
    Width="27%">
    <InsertItemTemplate>
    <table id="InsertItemTable" runat="server" style="width: 656px">
    <tr>
    <td style="width: 703px">
    <asp:panel ID="InsertDealerInfoPanel" runat="server"
    GroupingText="Dealer Info" Width="700px">
    <table id="InsertDealerInfoTable" runat="server"
    style="width: 672px">
    <tr>
    <td style="width: 138px">
    OGC ID:
    </td>
    <td style="width: 214px">
    <asp:Label ID="OGCIDLabel" runat="server" Text='New'></
    asp:Label>
    </td>
    </tr>
    <tr>
    <td style="width: 138px">
    Contact Name:</td>
    <td style="width: 214px">
    <asp:TextBox ID="NameTextBox" runat="server" Text='<%#
    Bind("Name") %>' Width="300px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
    runat="server" ControlToValidate="NameTextBox"
    Display="Dynamic" ErrorMessage="Contact Name is reqired."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Company Name:</td>
    <td style="width: 214px">
    <asp:TextBox ID="CompanyTextBox" runat="server" Text='<%#
    Bind("Company") %>' Width="300px"></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Company Type:</td>
    <td style="width: 214px">
    <asp:RadioButton ID="CorporationRadioBtn" runat="server"
    GroupName="BusinessType" Text="Corporation" />&nbsp;&nbsp;
    <asp:RadioButton ID="NonCorporationRadioBtn"
    runat="server" GroupName="BusinessType" Text="Non-Corporate Entity" /
    >&nbsp;

    <asp:TextBox ID="Is1099TextBox" runat="server" Text='<%#
    Eval("Is_1099") %>' Visible="False"></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 138px; height: 26px;">
    Phone:</td>
    <td style="width: 214px; height: 26px;">
    <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%#
    Bind("Phone") %>' Width="152px" MaxLength="10"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4"
    runat="server" ControlToValidate="PhoneTextBox"
    Display="Dynamic" ErrorMessage="Phone is required."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Fax:</td>
    <td style="width: 214px">
    <asp:TextBox ID="FaxTextBox" runat="server" Text='<%#
    Eval("FaxNumber") %>' Width="152px" MaxLength="10"></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Cell Phone:</td>
    <td style="width: 214px">
    <asp:TextBox ID="CellPhoneTextBox" runat="server" Text='<
    %# Eval("CellPhone") %>' Width="152px" MaxLength="10"></asp:TextBox></
    td>
    </tr>
    <tr>
    <td style="width: 138px">
    Email Address:</td>
    <td style="width: 214px">
    <asp:TextBox ID="EmailTextBox" runat="server" Text='<%#
    Eval("EmailAddress") %>' Width="300px"></asp:TextBox><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator5"
    runat="server" ControlToValidate="EmailTextBox"
    Display="Dynamic" ErrorMessage="Email Address is
    required." ValidationGroup="Insert"></
    asp:RequiredFieldValidator><asp:RegularExpressionValidator
    ID="RegularExpressionValidator1" runat="server"
    ControlToValidate="EmailTextBox"
    Display="Dynamic" ErrorMessage="You must enter a valid
    email address." Width="296px" ValidationExpression="\w+([-+.']\w+)*@\w+
    ([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Tax ID or Social Security:</td>
    <td style="width: 214px">
    <asp:TextBox ID="TaxIDTextBox" runat="server" Text='<%#
    Eval("TaxID") %>' Width="152px" MaxLength="9"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
    runat="server" ControlToValidate="TaxIDTextBox"
    Display="Dynamic" ErrorMessage="Please enter a valid
    Federal Tax ID or SS Number." ValidationGroup="Insert" Width="376px"></
    asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 138px;
    height: 26px">
    User ID:</td>
    <td style="width: 214px;
    height: 26px">
    <asp:TextBox
    ID="UserIDTextBox" runat="server"></asp:TextBox><br />

    <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    runat="server" ControlToValidate="UserIDTextBox"
    Display="Dynamic"
    ErrorMessage="User ID is a required field."></
    asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Password:</td>
    <td style="width: 214px">
    <asp:TextBox
    ID="PwdTextBox" runat="server" TextMode="Password"></asp:TextBox>
    <br />

    <asp:RequiredFieldValidator ID="RequiredFieldValidator3"
    runat="server" ControlToValidate="PwdTextBox"
    Display="Dynamic"
    ErrorMessage="Password is a required field."></
    asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 138px;
    height: 26px;">
    Confirm Password:</td>
    <td style="width: 214px;
    height: 26px;">
    <asp:TextBox
    ID="ConfirmPwdTextBox" runat="server" TextMode="Password"></
    asp:TextBox><br />

    <asp:RequiredFieldValidator ID="RequiredFieldValidator8"
    runat="server" ControlToValidate="ConfirmPwdTextBox"
    Display="Dynamic"
    ErrorMessage="Confirm Password is a required field."></
    asp:RequiredFieldValidator><br />
    <asp:CompareValidator
    ID="CompareValidator1" runat="server" ControlToCompare="PwdTextBox"

    ControlToValidate="ConfirmPwdTextBox" Display="Dynamic"
    ErrorMessage="Password and Confirm Password do not match."></
    asp:CompareValidator></td>
    </tr>
    </table>
    </asp:panel>
    </td>
    </tr>
    <tr>
    <td style="width: 703px">
    <asp:panel ID="InsertDealerAddressPanel" runat="server"
    GroupingText="Address" Width="700px">
    <table id="InsertDealerAddressTable" runat="server"
    style="width: 672px">
    <tr>
    <td style="width: 125px">
    Address:</td>
    <td style="width: 214px">
    <asp:TextBox ID="Address1TextBox" runat="server" Text='<%#
    Bind("Address1") %>' Width="300px"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
    runat="server" ControlToValidate="Address1TextBox"
    Display="Dynamic" ErrorMessage="Address is required."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px; height: 26px;">
    </td>
    <td style="width: 214px; height: 26px;">
    <asp:TextBox ID="Address2TextBox" runat="server" Text='<%#
    Bind("Address2") %>' Width="300px"></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 125px">
    City:</td>
    <td style="width: 214px">
    <asp:TextBox ID="CityTextBox" runat="server" Text='<%#
    Bind("City") %>' Width="176px" MaxLength="25"></asp:TextBox><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator11"
    runat="server" ControlToValidate="CityTextBox"
    Display="Dynamic" ErrorMessage="City is required."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px; height: 26px;">
    State/Province:</td>
    <td style="width: 214px; height: 26px;">
    <asp:DropDownList ID="StateDropDown" runat="server"
    DataSourceID="SqlDataSource1" DataTextField="description"
    DataValueField="state" Width="176px">
    <asp:ListItem
    Selected="True"></asp:ListItem>
    </asp:DropDownList><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator10"
    runat="server" ControlToValidate="StateDropDown"
    Display="Dynamic" ErrorMessage="Please choose a state."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px; height: 45px;">
    Postal Code:</td>
    <td style="width: 214px; height: 45px;">
    <asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<
    %# Bind("PostalCode") %>' Width="176px" MaxLength="10"></
    asp:TextBox><br />
    <asp:RequiredFieldValidator
    ID="RequiredFieldValidator9" runat="server"
    ControlToValidate="PostalCodeTextBox" Display="Dynamic"
    ErrorMessage="Postal Code is required."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px">
    Country:</td>
    <td style="width: 214px">
    <asp:DropDownList ID="CountryDropDown" runat="server"
    Width="176px">
    <asp:ListItem Selected="True"></asp:ListItem>
    <asp:ListItem>United States</asp:ListItem>
    <asp:ListItem>Canada</asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator12"
    runat="server" ControlToValidate="CountryDropDown"
    Display="Dynamic" ErrorMessage="Please choose a Country."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    </table>
    </asp:panel>
    </td>
    </tr>
    <tr>
    <td style="width: 703px">
    <asp:panel ID="InsertDealerAccountPanel" runat="server"
    GroupingText="Bank Account" Width="700px">
    <table id="InsertDealerAccountTable" runat="server"
    style="width: 672px">
    <tr>
    <td style="width: 125px">
    Account Number:</td>
    <td style="width: 214px">
    <asp:TextBox ID="AccountTextBox" runat="server"
    Text='<%# Bind("Account") %>' Width="300px"
    MaxLength="20"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator15"
    runat="server" ControlToValidate="AccountTextBox"
    Display="Dynamic" ErrorMessage="Account Number is
    required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px">
    Routing Number:</td>
    <td style="width: 214px">
    <asp:TextBox ID="RoutingNumberTextBox" runat="server"
    Text='<%# Eval("RoutingNumber") %>' Width="176px" MaxLength="9"></
    asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator16"
    runat="server" ControlToValidate="RoutingNumberTextBox"
    Display="Dynamic" ErrorMessage="Routing Number is
    required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
    <td style="width: 125px">
    Account Currency:</td>
    <td style="width: 214px">
    <asp:DropDownList ID="CurrencyDropDown" runat="server"
    Width="96px">
    <asp:ListItem Selected="True"></asp:ListItem>
    <asp:ListItem>USD</asp:ListItem>
    <asp:ListItem>CND</asp:ListItem>
    </asp:DropDownList><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator17"
    runat="server" ControlToValidate="CurrencyDropDown"
    Display="Dynamic" ErrorMessage="Please select a currency
    for the account." Width="288px" ValidationGroup="Insert"></
    asp:RequiredFieldValidator></td>
    </tr>
    </table>
    </asp:panel>
    </td>
    </tr>
    <tr>
    <td style="width: 703px">
    <asp:panel ID="InsertDealerAdvancedPanel" runat="server"
    GroupingText="Advanced" Width="700px">
    <table id="InsertDealerAdvancedTable" runat="server"
    style="width: 672px">
    <tr>
    <td style="width: 90px">
    Salesman Level:</td>
    <td style="width: 218px">
    <asp:DropDownList ID="SalesmanLevelDropDown"
    runat="server" Width="96px">
    <asp:ListItem>Level 1</asp:ListItem>
    <asp:ListItem>Level 2</asp:ListItem>
    </asp:DropDownList></td>
    </tr>
    <tr>
    <td style="width: 90px">
    Territory Manager:</td>
    <td style="width: 218px">
    <asp:DropDownList ID="TerritoryMgrDropDown" runat="server"
    DataSourceID="TMObjectDataSource" DataTextField="Name"
    DataValueField="SalesmanID" Width="176px"
    AutoPostBack="True">
    </asp:DropDownList><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator14"
    runat="server" ControlToValidate="TerritoryMgrDropDown"
    Display="Dynamic" ErrorMessage="Please choose a TM."
    ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    </tr>
    </table>
    </asp:panel>
    </td>
    </tr>
    </table>
    </InsertItemTemplate>



    Code behind:

    Protected Sub ModalOkButton_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles ModalOkButton.Click
    Try


    With Me.FormView1
    .ChangeMode(FormViewMode.Insert)
    .Visible = True
    End With

    With Me.TextBox1
    .Text = ""
    .Visible = False
    End With

    Me.SearchButton.Visible = False
    Me.lnkInsertTop.Visible = True
    Me.lnkInsertBottom.Visible = True
    Me.lnkEditTop.Visible = False
    Me.lnkEditBottom.Visible = False
    Me.lnkUpdateTop.Visible = False
    Me.lnkUpdateBottom.Visible = False
    Me.lnkCancelTop.Visible = True
    Me.lnkCancelBottom.Visible = True


    Dim TMDropDown As DropDownList

    TMDropDown =
    Me.FormView1.FindControl("TerritoryMgrDropDown")

    If UserInfo.IsInRole("TM") Then
    TMDropDown.SelectedValue =
    UserInfo.Profile.GetPropertyValue("SalesmanID")


    Else
    TMDropDown.Visible = True
    End If
    Trace.Write(TMDropDown.Visible.ToString)
    Trace.Write(TMDropDown.SelectedValue.ToString)


    Catch ex As Exception
    Throw ex
    End Try
    End Sub

    Thanks,
    Hollywood
    Hollywood, Feb 7, 2008
    #1
    1. Advertising

  2. Hollywood

    Hollywood Guest

    Re: Can't visible property of DropDownList in FormView control

    On Feb 7, 12:45 pm, Hollywood <> wrote:
    > I have a formview control that contains a dropdownlist (nested in a
    > panel) and I want to set the visible property to False when the user
    > is in a particular role. I'm using a modal popup button click event
    > to fire the change, and I set the formview mode to Insert and that
    > works great. Just after that I try to set the dropdownlist.visible =
    > false (or true depending) and I can find the control okay but it never
    > sets the visibility.
    >
    > I've been chasing after this for a couple of days and any help would
    > really be appreciated!! :)
    >
    > Here's the code:
    >
    > aspx page:
    >
    > <asp:FormView ID="FormView1" runat="server" DataSourceID="Dealer"
    > Width="27%">
    > <InsertItemTemplate>
    > <table id="InsertItemTable" runat="server" style="width: 656px">
    > <tr>
    > <td style="width: 703px">
    > <asp:panel ID="InsertDealerInfoPanel" runat="server"
    > GroupingText="Dealer Info" Width="700px">
    > <table id="InsertDealerInfoTable" runat="server"
    > style="width: 672px">
    > <tr>
    > <td style="width: 138px">
    > OGC ID:
    > </td>
    > <td style="width: 214px">
    > <asp:Label ID="OGCIDLabel" runat="server" Text='New'></
    > asp:Label>
    > </td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Contact Name:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="NameTextBox" runat="server" Text='<%#
    > Bind("Name") %>' Width="300px"></asp:TextBox>
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
    > runat="server" ControlToValidate="NameTextBox"
    > Display="Dynamic" ErrorMessage="Contact Name is reqired."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Company Name:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="CompanyTextBox" runat="server" Text='<%#
    > Bind("Company") %>' Width="300px"></asp:TextBox></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Company Type:</td>
    > <td style="width: 214px">
    > <asp:RadioButton ID="CorporationRadioBtn" runat="server"
    > GroupName="BusinessType" Text="Corporation" />&nbsp;&nbsp;
    > <asp:RadioButton ID="NonCorporationRadioBtn"
    > runat="server" GroupName="BusinessType" Text="Non-Corporate Entity" />&nbsp;
    >
    > <asp:TextBox ID="Is1099TextBox" runat="server" Text='<%#
    > Eval("Is_1099") %>' Visible="False"></asp:TextBox></td>
    > </tr>
    > <tr>
    > <td style="width: 138px; height: 26px;">
    > Phone:</td>
    > <td style="width: 214px; height: 26px;">
    > <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%#
    > Bind("Phone") %>' Width="152px" MaxLength="10"></asp:TextBox>
    > <br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator4"
    > runat="server" ControlToValidate="PhoneTextBox"
    > Display="Dynamic" ErrorMessage="Phone is required."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Fax:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="FaxTextBox" runat="server" Text='<%#
    > Eval("FaxNumber") %>' Width="152px" MaxLength="10"></asp:TextBox></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Cell Phone:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="CellPhoneTextBox" runat="server" Text='<
    > %# Eval("CellPhone") %>' Width="152px" MaxLength="10"></asp:TextBox></
    > td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Email Address:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="EmailTextBox" runat="server" Text='<%#
    > Eval("EmailAddress") %>' Width="300px"></asp:TextBox><br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator5"
    > runat="server" ControlToValidate="EmailTextBox"
    > Display="Dynamic" ErrorMessage="Email Address is
    > required." ValidationGroup="Insert"></
    > asp:RequiredFieldValidator><asp:RegularExpressionValidator
    > ID="RegularExpressionValidator1" runat="server"
    > ControlToValidate="EmailTextBox"
    > Display="Dynamic" ErrorMessage="You must enter a valid
    > email address." Width="296px" ValidationExpression="\w+([-+.']\w+)*@\w+
    > ([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Tax ID or Social Security:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="TaxIDTextBox" runat="server" Text='<%#
    > Eval("TaxID") %>' Width="152px" MaxLength="9"></asp:TextBox>
    > <br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
    > runat="server" ControlToValidate="TaxIDTextBox"
    > Display="Dynamic" ErrorMessage="Please enter a valid
    > Federal Tax ID or SS Number." ValidationGroup="Insert" Width="376px"></
    > asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px;
    > height: 26px">
    > User ID:</td>
    > <td style="width: 214px;
    > height: 26px">
    > <asp:TextBox
    > ID="UserIDTextBox" runat="server"></asp:TextBox><br />
    >
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    > runat="server" ControlToValidate="UserIDTextBox"
    > Display="Dynamic"
    > ErrorMessage="User ID is a required field."></
    > asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px">
    > Password:</td>
    > <td style="width: 214px">
    > <asp:TextBox
    > ID="PwdTextBox" runat="server" TextMode="Password"></asp:TextBox>
    > <br />
    >
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator3"
    > runat="server" ControlToValidate="PwdTextBox"
    > Display="Dynamic"
    > ErrorMessage="Password is a required field."></
    > asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 138px;
    > height: 26px;">
    > Confirm Password:</td>
    > <td style="width: 214px;
    > height: 26px;">
    > <asp:TextBox
    > ID="ConfirmPwdTextBox" runat="server" TextMode="Password"></
    > asp:TextBox><br />
    >
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator8"
    > runat="server" ControlToValidate="ConfirmPwdTextBox"
    > Display="Dynamic"
    > ErrorMessage="Confirm Password is a required field."></
    > asp:RequiredFieldValidator><br />
    > <asp:CompareValidator
    > ID="CompareValidator1" runat="server" ControlToCompare="PwdTextBox"
    >
    > ControlToValidate="ConfirmPwdTextBox" Display="Dynamic"
    > ErrorMessage="Password and Confirm Password do not match."></
    > asp:CompareValidator></td>
    > </tr>
    > </table>
    > </asp:panel>
    > </td>
    > </tr>
    > <tr>
    > <td style="width: 703px">
    > <asp:panel ID="InsertDealerAddressPanel" runat="server"
    > GroupingText="Address" Width="700px">
    > <table id="InsertDealerAddressTable" runat="server"
    > style="width: 672px">
    > <tr>
    > <td style="width: 125px">
    > Address:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="Address1TextBox" runat="server" Text='<%#
    > Bind("Address1") %>' Width="300px"></asp:TextBox>
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
    > runat="server" ControlToValidate="Address1TextBox"
    > Display="Dynamic" ErrorMessage="Address is required."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px; height: 26px;">
    > </td>
    > <td style="width: 214px; height: 26px;">
    > <asp:TextBox ID="Address2TextBox" runat="server" Text='<%#
    > Bind("Address2") %>' Width="300px"></asp:TextBox></td>
    > </tr>
    > <tr>
    > <td style="width: 125px">
    > City:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="CityTextBox" runat="server" Text='<%#
    > Bind("City") %>' Width="176px" MaxLength="25"></asp:TextBox><br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator11"
    > runat="server" ControlToValidate="CityTextBox"
    > Display="Dynamic" ErrorMessage="City is required."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px; height: 26px;">
    > State/Province:</td>
    > <td style="width: 214px; height: 26px;">
    > <asp:DropDownList ID="StateDropDown" runat="server"
    > DataSourceID="SqlDataSource1" DataTextField="description"
    > DataValueField="state" Width="176px">
    > <asp:ListItem
    > Selected="True"></asp:ListItem>
    > </asp:DropDownList><br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator10"
    > runat="server" ControlToValidate="StateDropDown"
    > Display="Dynamic" ErrorMessage="Please choose a state."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px; height: 45px;">
    > Postal Code:</td>
    > <td style="width: 214px; height: 45px;">
    > <asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<
    > %# Bind("PostalCode") %>' Width="176px" MaxLength="10"></
    > asp:TextBox><br />
    > <asp:RequiredFieldValidator
    > ID="RequiredFieldValidator9" runat="server"
    > ControlToValidate="PostalCodeTextBox" Display="Dynamic"
    > ErrorMessage="Postal Code is required."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px">
    > Country:</td>
    > <td style="width: 214px">
    > <asp:DropDownList ID="CountryDropDown" runat="server"
    > Width="176px">
    > <asp:ListItem Selected="True"></asp:ListItem>
    > <asp:ListItem>United States</asp:ListItem>
    > <asp:ListItem>Canada</asp:ListItem>
    > </asp:DropDownList>
    > <br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator12"
    > runat="server" ControlToValidate="CountryDropDown"
    > Display="Dynamic" ErrorMessage="Please choose a Country."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > </table>
    > </asp:panel>
    > </td>
    > </tr>
    > <tr>
    > <td style="width: 703px">
    > <asp:panel ID="InsertDealerAccountPanel" runat="server"
    > GroupingText="Bank Account" Width="700px">
    > <table id="InsertDealerAccountTable" runat="server"
    > style="width: 672px">
    > <tr>
    > <td style="width: 125px">
    > Account Number:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="AccountTextBox" runat="server"
    > Text='<%# Bind("Account") %>' Width="300px"
    > MaxLength="20"></asp:TextBox>
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator15"
    > runat="server" ControlToValidate="AccountTextBox"
    > Display="Dynamic" ErrorMessage="Account Number is
    > required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px">
    > Routing Number:</td>
    > <td style="width: 214px">
    > <asp:TextBox ID="RoutingNumberTextBox" runat="server"
    > Text='<%# Eval("RoutingNumber") %>' Width="176px" MaxLength="9"></
    > asp:TextBox>
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator16"
    > runat="server" ControlToValidate="RoutingNumberTextBox"
    > Display="Dynamic" ErrorMessage="Routing Number is
    > required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > <tr>
    > <td style="width: 125px">
    > Account Currency:</td>
    > <td style="width: 214px">
    > <asp:DropDownList ID="CurrencyDropDown" runat="server"
    > Width="96px">
    > <asp:ListItem Selected="True"></asp:ListItem>
    > <asp:ListItem>USD</asp:ListItem>
    > <asp:ListItem>CND</asp:ListItem>
    > </asp:DropDownList><br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator17"
    > runat="server" ControlToValidate="CurrencyDropDown"
    > Display="Dynamic" ErrorMessage="Please select a currency
    > for the account." Width="288px" ValidationGroup="Insert"></
    > asp:RequiredFieldValidator></td>
    > </tr>
    > </table>
    > </asp:panel>
    > </td>
    > </tr>
    > <tr>
    > <td style="width: 703px">
    > <asp:panel ID="InsertDealerAdvancedPanel" runat="server"
    > GroupingText="Advanced" Width="700px">
    > <table id="InsertDealerAdvancedTable" runat="server"
    > style="width: 672px">
    > <tr>
    > <td style="width: 90px">
    > Salesman Level:</td>
    > <td style="width: 218px">
    > <asp:DropDownList ID="SalesmanLevelDropDown"
    > runat="server" Width="96px">
    > <asp:ListItem>Level 1</asp:ListItem>
    > <asp:ListItem>Level 2</asp:ListItem>
    > </asp:DropDownList></td>
    > </tr>
    > <tr>
    > <td style="width: 90px">
    > Territory Manager:</td>
    > <td style="width: 218px">
    > <asp:DropDownList ID="TerritoryMgrDropDown" runat="server"
    > DataSourceID="TMObjectDataSource" DataTextField="Name"
    > DataValueField="SalesmanID" Width="176px"
    > AutoPostBack="True">
    > </asp:DropDownList><br />
    > <asp:RequiredFieldValidator ID="RequiredFieldValidator14"
    > runat="server" ControlToValidate="TerritoryMgrDropDown"
    > Display="Dynamic" ErrorMessage="Please choose a TM."
    > ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
    > </tr>
    > </table>
    > </asp:panel>
    > </td>
    > </tr>
    > </table>
    > </InsertItemTemplate>
    >
    > Code behind:
    >
    > Protected Sub ModalOkButton_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles ModalOkButton.Click
    > Try
    >
    > With Me.FormView1
    > .ChangeMode(FormViewMode.Insert)
    > .Visible = True
    > End With
    >
    > With Me.TextBox1
    > .Text = ""
    > .Visible = False
    > End With
    >
    > Me.SearchButton.Visible = False
    > Me.lnkInsertTop.Visible = True
    > Me.lnkInsertBottom.Visible = True
    > Me.lnkEditTop.Visible = False
    > Me.lnkEditBottom.Visible = False
    > Me.lnkUpdateTop.Visible = False
    > Me.lnkUpdateBottom.Visible = False
    > Me.lnkCancelTop.Visible = True
    > Me.lnkCancelBottom.Visible = True
    >
    > Dim TMDropDown As DropDownList
    >
    > TMDropDown =
    > Me.FormView1.FindControl("TerritoryMgrDropDown")
    >
    > If UserInfo.IsInRole("TM") Then
    > TMDropDown.SelectedValue =
    > UserInfo.Profile.GetPropertyValue("SalesmanID")
    >
    > Else
    > TMDropDown.Visible = True
    > End If
    > Trace.Write(TMDropDown.Visible.ToString)
    > Trace.Write(TMDropDown.SelectedValue.ToString)
    >
    > Catch ex As Exception
    > Throw ex
    > End Try
    > End Sub
    >
    > Thanks,
    > Hollywood


    Sorry gang - I was testing if the .visible was the issue or not.
    Based on the trace, .visible does get set to False but when the
    control renders, it is visible. It's in the InsertItem template. The
    code behind looks like this:

    Protected Sub ModalOkButton_Click(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles ModalOkButton.Click
    Try


    With Me.FormView1
    .ChangeMode(FormViewMode.Insert)
    .Visible = True
    End With

    With Me.TextBox1
    .Text = ""
    .Visible = False
    End With

    Me.SearchButton.Visible = False
    Me.lnkInsertTop.Visible = True
    Me.lnkInsertBottom.Visible = True
    Me.lnkEditTop.Visible = False
    Me.lnkEditBottom.Visible = False
    Me.lnkUpdateTop.Visible = False
    Me.lnkUpdateBottom.Visible = False
    Me.lnkCancelTop.Visible = True
    Me.lnkCancelBottom.Visible = True


    Dim TMDropDown As DropDownList

    TMDropDown =
    Me.FormView1.FindControl("TerritoryMgrDropDown")

    If UserInfo.IsInRole("TM") Then
    TMDropDown.Visible = False


    Else
    TMDropDown.Visible = True
    End If
    Trace.Write(TMDropDown.Visible.ToString)
    Trace.Write(TMDropDown.SelectedValue.ToString)


    Catch ex As Exception
    Throw ex
    End Try
    End Sub
    Hollywood, Feb 7, 2008
    #2
    1. Advertising

  3. Hollywood

    Hollywood Guest

    Re: Can't visible property of DropDownList in FormView control

    I figured out how to make this work. I tried using FormView's
    ItemCreated event before but forgot to check to see if CurrentMode =
    Insert. Once I did that, it found the control and I could set its
    properties.

    New code:

    Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal
    e As System.EventArgs) Handles FormView1.ItemCreated
    Try
    If Me.FormView1.CurrentMode = FormViewMode.Insert Then
    Dim TMDropDown As DropDownList
    TMDropDown =
    Me.FormView1.FindControl("TerritoryMgrDropDown")

    If UserInfo.IsInRole("TM") Then
    TMDropDown.Enabled = False
    TMDropDown.SelectedValue =
    UserInfo.Profile.GetPropertyValue("SalesmanID")

    Else
    TMDropDown.Visible = True
    End If
    End If

    Catch ex As Exception
    Throw ex
    End Try

    End Sub


    Hope this helps sombody else!

    HW
    Hollywood, Feb 7, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spamfurnace
    Replies:
    1
    Views:
    2,631
    Scott M.
    May 24, 2004
  2. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,442
    Brian Hoops
    Oct 28, 2004
  3. Andrea Williams

    User control not visible when setting .Visible = true;

    Andrea Williams, Jan 26, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    508
    Andrea Williams
    Jan 28, 2004
  4. Jurjen de Groot
    Replies:
    0
    Views:
    300
    Jurjen de Groot
    May 19, 2008
  5. Lagrange
    Replies:
    1
    Views:
    553
    Lagrange
    Jan 17, 2009
Loading...

Share This Page