Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 757917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:25:07+00:00 2026-05-14T15:25:07+00:00

NB. I am going to be away until Tuesday next week. So all help

  • 0

NB. I am going to be away until Tuesday next week. So all help is appreciated but I will be unable to comment/respond until then.

I have a FormView that modifies an instance of a custom class. The various form controls (TextBox, DropDownList etc.) are working fine. However, I want to include a Button that will modify the state of the DataItem based on some very simple logic. There is no form control which could control this change in a non-confusing way.

The actual situation is I have a form for entering an address. The address might be a “standard” Australian address (street # and name, suburb state and postcode) or it might be “non-standard” which means it has 3 address lines before suburb (for people with more specific address requirements). I want a button that says “add more lines” and clicking it will change the object from being AddressLines.StandardAustralian to AddressLines.NonStandardAustralian. For non-standard addresses there will be another button that says “Remove extra lines” and clicking that will reverse the process.

So I tried adding a Button and modifying the state of the DataItem in the code-behind. But the problem I encounter is that the FormView’s DataItem is null/nothing. From reading this SO question it seems the problem is that the item is not databound when the Button’s Click event is fired.

So, the question; Is it possible to get the DataItem for the FormView during a Button’s Click event? and if not: what are my options for implementing this?

Thanks in advance.

Code Behind:

Private ReadOnly Property addressView() As AddressView
    Get
        Return CType(FormView1.DataItem, AddressView) ' <-- But DataItem is Nothing when called from lbMakeNonStd_Click
    End Get
End Property

Protected Sub lbMakeNonStd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbMakeNonStd.Click
    If addressView IsNot Nothing Then

        Select Case addressView.NonStd
            Case AddressLines.StandardAustralian
                addressView.NonStd = AddressLines.NonStandardAustralian

            Case AddressLines.NonStandardAustralian
                addressView.NonStd = AddressLines.StandardAustralian

            Case Else
                ' Other cases ignored, shouldn't change address lines
        End Select
    End If
End Sub

Aspx:

<asp:FormView ID="FormView1" runat="server" DataKeyNames="IDNO, AddressType" DataSourceID="ObjectDataSource1" EnableViewState="true" >
<ItemTemplate>
    ...
</ItemTemplate>
<EditItemTemplate>
    <fieldset>
    <legend>Address</legend>
    <asp:UpdatePanel ID="upAddressFields" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="txtPostcode" eventname="TextChanged" />
    </Triggers>
    <ContentTemplate>
    <asp:Table ID="tblForm" runat="server">
        <asp:TableRow ID="trName" runat="server">
            <asp:TableHeaderCell ID="TableCell1" runat="server">
                Name
            </asp:TableHeaderCell>
            <asp:TableCell ID="TableCell2" runat="server">
                <asp:TextBox ID="tbName" runat="server" Text='<%# Bind("AlternateName") %>' MaxLength="30"></asp:TextBox>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow ID="TableRow2" runat="server" Cs>
            <asp:TableHeaderCell ID="TableCell3" runat="server">
                Number and Street
            </asp:TableHeaderCell>
            <asp:TableCell ID="TableCell4" runat="server">
                <asp:TextBox ID="tbLine1" runat="server" Text='<%# Bind("Line1") %>' MaxLength="30"></asp:TextBox>
                <asp:PlaceHolder ID="phMakeNonStdButton" runat="server">(<asp:LinkButton ID="lbMakeNonStd" runat="server" Text="Add more lines..." />)</asp:PlaceHolder>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow ID="trLine2" runat="server" CssClass="tablerowbg_light">
            <asp:TableHeaderCell ID="TableCell5" runat="server">
                Line 2
            </asp:TableHeaderCell>
            <asp:TableCell ID="TableCell6" runat="server">
                <asp:TextBox ID="tbLine2" runat="server" Text='<%# Bind("Line2") %>' MaxLength="30"></asp:TextBox>
                <br /><asp:LinkButton ID="lbMakeStd" runat="server" Text="Use fewer lines..." />
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    </ContentTemplate>
    </asp:UpdatePanel>
    <asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update" ValidationGroup="ResidentialAddress" Font-Bold="true">Save Changes</asp:LinkButton> |
    <asp:LinkButton ID="lbCancel" runat="server" CommandName="Cancel" CausesValidation="false">Cancel</asp:LinkButton>
</EditItemTemplate>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:25:07+00:00Added an answer on May 14, 2026 at 3:25 pm

    Ok, so I have this working. Perhaps not the best way it could be done it works.

    Basically I added a hidden field bound to the value I wanted to change. Then in the button’s click event method I modified the value of the hidden field and let the FormView update the custom class. This is instead of getting the DataItem from the FormView and modifying it directly as I was trying at the start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is VBA going to go away any time soon, like VB6 has? Should I
Going back to my previous question on OCSP, does anybody know of reliable OCSP
While going through university and from following the development of SO, I've heard a
Been going over my predecessor's code and see usage of the request scope frequently.
After going through the Appendix A, C# Coding Style Conventions of the great book
What's going on here? printf.sh: #! /bin/sh NAME=George W. Bush printf Hello, %s\n $NAME
I'm going to start a new project - rewriting an existing system (PHP +
I am going to be using C/C++, and would like to know the best
I'm going to build an API for a web app and I'm interested in
Is my best be going to be a shell script which replaces symlinks with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.