Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

Databind problem

$
0
0

I can't seem to get a simple .NET application to recognize a databound control.  Basically I have a .NET application, this time in Visual Basic, with an Entity build from an existing database.  When I have tags like the following, I can't get it to do anything.

            <div>
                <asp:TextBox ID="tbServiceRequestDate" runat="server" Text='<%# Bind("ServiceRequestDate") %>'></asp:TextBox>
            </div>

Code behind:

    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            tbServiceRequestDate.DataBind()
        Else
            tbServiceRequestDate.DataBind()
        End If

    End Sub

    Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
        tbServiceRequestDate.DataBind()
    End Sub

The Entity is basically EHSShipping.

I get this error:

System.InvalidOperationException
  HResult=0x80131509
  Message=Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
  Source=App_Web_5tsnn3n3
  StackTrace:
   at ASP.default_aspx.__DataBindingtbServiceRequestDate(Object sender, EventArgs e) in C:\dev\EHSShipping\EHSShipping\Default.aspx:line 14
   at _Default.Page_Load(Object Sender, EventArgs e) in C:\dev\EHSShipping\EHSShipping\Default.aspx.vb:line 7

What I'm trying to do is databind the controls as text boxes and select boxes (eventually, a radio button or a checkbox), and have a submit button that takes all the form data and updates the database through the entities.  Once I get that working, then I'm going to build a grid control that shows all the various forms as individual records in the system that can be selected and viewed.

I figure once I get the TextBox to work right, I can do the other controls pretty easy, however, right now I'm having a hard time getting that one TextBox to update the database on submit.  Keep in mind there is an ID that is unique in the database, but I was assuming the Entity Framework handles that automatically and just inserts the rows as the columns are referenced in the Bind commands...

Please advise...


Viewing all articles
Browse latest Browse all 956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>