Textbox value in the edittemplate of a datalist doesn't report the changes

  • Thread starter Thread starter Antonio D'Ottavio
  • Start date Start date
A

Antonio D'Ottavio

Good Morning,
I've a problem with a textfiled inside a datalist, in particular it's value
it is not updated with the changes,
I mean sNomeCampo has still the value coming from the dB and not that
changed by the user,
May you help me ???

Antonio D'Ottavio
www.etantonio.it/en

Here's the code :


void Update_Command(Object sender, DataListCommandEventArgs e)
{
String sNomeCampo =
((TextBox)e.Item.FindControl("NomeCampo")).Text;
}



<ASP:DataList id="MyDataCampi" runat="server" HorizontalAlign="Center"
RepeatDirection="Horizontal" RepeatColumns="1"
OnEditCommand="Edit_Command" OnUpdateCommand="Update_Command"
OnDeleteCommand="Delete_Command" OnCancelCommand="Cancel_Command"
OnItemDataBound="BindComboes"
<ItemTemplate>
<tr style="background-color:CCFF99">
<td width=10% align="center">
<asp:LinkButton id="EditButton" Text="Edit"
CommandName="Edit" runat="server"/>
<input id="HiddenIDCampo" type="hidden" value='<%#
DataBinder.Eval(Container.DataItem, "IDCampo") %>' runat="server" />
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"NomeCampo")%>
</td>
</tr>
</ItemTemplate>

<EditItemTemplate>
<asp:LinkButton id="UpdateButton"
Text="Update"
CommandName="Update"
runat="server"/>

<td>
<asp:TextBox id="NomeCampo"
Text='<%# DataBinder.Eval(Container.DataItem,
"NomeCampo") %>'
runat="server"/>
</td>
</EditItemTemplate>

</ASP:DataList>
 
I am not sure where you are going with this, so let's just cover the basics
of data CRUD in ADO.NET with ASP.NET and see if it helps.

1. Get data
a) Set up command, connection, dataAdapter and DataSet objects
b) (optional, but recommended) - map the generic tables in the
DataAdapter to more useful names
c) Use Fill() on the DataAdapter to fill the data set
2. Fill the container - in your case, a DataList
3. User updates data
4. User submits form
5. Call Update on the DataAdapter to update data
6. Rebind the container with current data

Try this:
http://www.dotnetjohn.com/articles.aspx?articleid=17

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Hi Antonio,

The most possible reason to cause this kind problem is that the value in the
textbox is overwritten by value from DB (The datalist’s data source is
rebound.) before conducting update.

So make sure only binding data source when is not pastback:

if (!IsPostback)
{
Datalist.DataSource = datasource_Object;
Datalist..DataBind();
}

HTH

Elton Wang
 
Back
Top