When/Where to load data in DataList Update Template

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a datalist where I'm using the edit/update/cancel commands to update
an item in the list. When I click on the edit button the update template
loads OK and all the controls are displaying correctly. My question is
where do I load or populate the controls? In other words, is there a
specific event where I should be populating these controls or can I call a
method from the Page_Load event? I'm working in vb.net 1.1.

Thanks
 
I figured it out. I was looking in the codebehind for a place to bind or
populate a textbox in the edit template with data, but I found I could do it
in the template itself by binding it there. There was a problem though,
when I tried to bind it using the properties window, it would error saying
something like you cant assign text to an integer. I don't understand what
that was about, but when I coded it by hand it worked. Here's the code in
the template:

<asp:Textbox id=txtFName runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "FName")%>'
CssClass="clsAddressListingBodyText"></asp:TextBox>

Where 'FName' is a field in the dataset that I was using to bind the
datalist with.
 
Hi moondaddy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to find a place to bind the
textbox to certain data sources. However, when you bind the controls to a
dataset in the properties windows, an error saying something like "you
cant assign text to an integer" was raised. If there is any
misunderstanding, please feel free to let me know.

I think you can load you data in the Page_Load event by calling the
DataAdapter.Fill method. When the data are loaded to the DataSet, call
TextBox.DataBind and the data will be displayed on the control.

Generally, when you received an error saying that "you can't assign text to
an integer" in simple binding, I think you have binded the wrong property
to data source. For example, you might have binded the TextBox.Height
property to a string field like 'FName'. This yields the following code:

<asp:Textbox id=txtFName runat="server" Height='<%#
DataBinder.Eval(Container.DataItem, "FName")%>'
CssClass="clsAddressListingBodyText"></asp:TextBox>

So please try to check if the data source has been bounded by the correct
property and designer has generated the correct binding code.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top