Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,961 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,522 people online right now. Registration is fast and FREE... Join Now!




Trying to update a field in an EditItemTemplate

 
Reply to this topicStart new topic

Trying to update a field in an EditItemTemplate, Field updates on display, but doesn't update database

stapes
22 May, 2008 - 07:08 AM
Post #1

New D.I.C Head
*

Joined: 22 May, 2008
Posts: 3

Hi I have this EditItemTemplate which starts like this:
CODE
<fieldset>

<legend>Edit Order Template</legend>

<div class="px112">

destination / site:

</div>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("destinationID") %>' Width="165px"

Enabled="False"></asp:TextBox> 

<asp:Label ID="lblDestinationName" runat="server" Text="destinationName:"></asp:Label>

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlAllSites" DataTextField="destinationName"

DataValueField="siteID" SelectedValue='<%# Eval("destinationID") %>' Enabled="False">

</asp:DropDownList>

<br />

<fieldset>

<legend>Update Destination</legend>

<asp:Label ID="Label2" runat="server" Text="To change destination, first select site type:"></asp:Label>

<asp:ObjectDataSource ID="ods_Sites" runat="server" OldValuesParameterFormatString="original_{0}"

SelectMethod="GetSiteTypes" TypeName="dsSiteTypesTableAdapters.SiteType_SelectTableAdapter"

OnSelecting="ods_Sites_Selecting"></asp:ObjectDataSource>

<asp:DropDownList ID="ddSiteTypes" runat="server" AppendDataBoundItems="True" DataSourceID="ods_Sites"

DataTextField="siteType" DataValueField="siteTypeID" Width="170px" ToolTip="Select site type .."

Height="23px">

<asp:ListItem Value="-1">Site type...</asp:ListItem>

</asp:DropDownList>

<asp:Label ID="Label1" runat="server" Text="new Destination Name"></asp:Label>

<asp:DropDownList ID="ddDestinationName" runat="server" DataSourceID="SqlAllSites"

DataTextField="destinationName" DataValueField="siteID" OnSelectedIndexChanged="ddDestinationName_SelectedIndexChanged">

</asp:DropDownList>

<asp:Button ID="buttUpdateDestination" runat="server" OnClick="buttUpdateDestination_Click"

Text="Update Destination" />

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="SiteType"

LoadingText="Please wait..." ParentControlID="ddSiteTypes" PromptText="Select a destination"

TargetControlID="ddDestinationName" ServicePath="sloDestinationService.asmx"

ServiceMethod="GetSloDestinations" />

</fieldset>


It starts with a text box showing the value of the field DestinationID.The next field is a DropDownList which displays the Destination Name linked to the ame value field DestinationID (SiteID).Next, there are two Cascading Drop Down boxes in the fieldset called Update Destination. The user chooses a Site Type. Then the list of destinations in ddDestinationName is changed to suit. The user chooses the destination name from the second Drop Down box, the clicks on the Update Destination button.That runs this code:
CODE
DropDownList myList = (DropDownList)fvSingleLineOrders.FindControl("ddDestinationName");
int number = Convert.ToInt32(myList.SelectedValue);

TextBox myText = (TextBox)fvSingleLineOrders.FindControl("TextBox1");
myText.Text = myList.SelectedValue;


Followed by this:
CODE
gvSingleLineOrders.DataSourceID = "SqlSingleLineOrderList";
gvSingleLineOrders.DataBind();


In testing, TextBox1 is being updated with the new value, but it is not reflected in the value displayed in DropDownList2 even though DestinationID should now be changed. Then, when the Update Order button is pressed, the database is not being updated. All other fields on the form update OK.
1. How do I make it update destinationID (the field bound to TextBox1)?
2. How do I get it to display the new value in DropDownList2?

Stapes
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:34AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month