I have a drop down list that selects a client. I wrote some code to retrieve the clients preferred order and want to then add that into the DetailsView, that is currently being editted.
The DetailsView is a standard details view with templated items (here is some code)
But the data does not get updated. I have a terrible feeling I have to popular Session variable and then use some sort of bind. However I am not even sure how to do that.
DataBind will overwrite things. So better not do that when you want to set data depending on DropDownList.
Have you used the debugger to check if the right data goes to the right TextBoxes?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Sorry for the late reply I had not got a notification. The data is there but explain how I check if the textboxes have been updated ?
I have sicne converted this system code to Access since we are sharing a database with the .net system, and the access system is working.
Here is the code for the complete dropdownlist event.
// defined at the top of the class
const string DV_CONTROL_CUSTOMER = "ddlCustomer";
const string DV_CONTROL_ORDER_DATE = "tbxDetailOrderDate";
const string DV_CONTROL_ROAST_DATE = "tbxDetailRoastDate";
const string DV_CONTROL_REQUIRED_BY_DATE = "tbxRequiredByDate";
const string DV_CONTROL_QTY = "tbxQuantity";
const string DV_CONTROL_ITEMDESC = "ddlItemDesc";
const string DV_CONTROL_DELIVERY_BY = "ddlDeliveryBy";
const string DV_CONTROL_CONFIRMED = "cbxConfirmed";
protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
// use the current customer and using their city get the next roast date for that city
TrackerDotNet.classes.TrackerTools tt = new classes.TrackerTools();
DropDownList _ddlCustomers = (DropDownList)sender;
// roast day vars
DateTime _dtNextRoastDay;
DateTime _dtDelivery = DateTime.Now;
// preference vars;
Int64 _CustID = Convert.ToInt64(_ddlCustomers.SelectedValue);
int _preferredDlvryBy = 1;
int _preferredItem = 1;
double _preferredQty = 1;
// get the next preparation date
_dtNextRoastDay = tt.GetNextRoastDateByCustomerID(_CustID, ref _dtDelivery);
tt.RetrieveCustomerPrefs(_CustID, ref _preferredDlvryBy, ref _preferredItem, ref _preferredQty);
((TextBox)dvOrderEdit.FindControl(DV_CONTROL_ROAST_DATE)).Text = String.Format("{0:d}",_dtNextRoastDay);
((TextBox)dvOrderEdit.FindControl(DV_CONTROL_REQUIRED_BY_DATE)).Text = String.Format("{0:d}",_dtDelivery);
((DropDownList)dvOrderEdit.FindControl(DV_CONTROL_DELIVERY_BY)).SelectedValue = _preferredDlvryBy.ToString();
(DropDownList)dvOrderEdit.FindControl(DV_CONTROL_ITEMDESC)).SelectedValue = _preferredItem.ToString();
((TextBox)dvOrderEdit.FindControl(DV_CONTROL_QTY)).Text = String.Format("{0:N}", _preferredQty);
/// dvOrderEdit.DataBind();
}
Handle the DataBound event of DetailsView to set these values to TextBox. Make sure the currentmode of DetailsView is in the edit or other mode you want.
Warren Macha...
Member
65 Points
50 Posts
Data does not update in DetailsView
May 17, 2012 04:02 PM|LINK
I have a drop down list that selects a client. I wrote some code to retrieve the clients preferred order and want to then add that into the DetailsView, that is currently being editted.
The DetailsView is a standard details view with templated items (here is some code)
<asp:DetailsView ID="dvOrderEdit" runat="server" AllowPaging="True" AutoGenerateRows="False" OnItemInserted="dvOrderEdit_OnItemInserted" DataKeyNames="OrderID" DataSourceID="odsOrderDetail" OnDataBound="dvOrderEdit_OnDataBound" EnablePagingCallbacks="True" ForeColor="Black" onpageindexchanging="dvOrderEdit_PageIndexChanging" > <AlternatingRowStyle BackColor="PaleGoldenrod" /> <CommandRowStyle HorizontalAlign="Center" VerticalAlign="Middle" /> <EditRowStyle BackColor="Honeydew" ForeColor="DarkOliveGreen" /> <Fields> <asp:CommandField ButtonType="Button" ShowEditButton="True" ShowInsertButton="True" /> <asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False" ReadOnly="True" SortExpression="OrderID" Visible="False" /> <asp:TemplateField HeaderText="Customer" SortExpression="CustomerId"> <EditItemTemplate> <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="odsCompanyNames" DataTextField="NameAndDetails" DataValueField="CustomerID" AppendDataBoundItems="true" SelectedValue='<%# Bind("CustomerId") %>' Font-Size="Small" AutoPostBack="true" onselectedindexchanged="ddlCustomer_SelectedIndexChanged"> <asp:ListItem Selected="True" Text="---Please select a Company---" Value="" /> </asp:DropDownList> </EditItemTemplate> <InsertItemTemplate> <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="odsCompanyNames" DataTextField="NameAndDetails" DataValueField="CustomerID" AppendDataBoundItems="true" SelectedValue='<%# Bind("CustomerId") %>' Font-Size="Small" AutoPostBack="true" onselectedindexchanged="ddlCustomer_SelectedIndexChanged"> <asp:ListItem Selected="True" Text="---Please select a Company---" Value="" /> </asp:DropDownList> </InsertItemTemplate> <ItemTemplate> <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="odsCompanyNames" DataTextField="CompanyName" DataValueField="CustomerID" Enabled="false" SelectedValue='<%# Bind("CustomerId") %>' Font-Size="Small" > </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Order Date" SortExpression="OrderDate"> <EditItemTemplate> <asp:TextBox ID="tbxDetailOrderDate" runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' /> <cc1:CalendarExtender ID="tbxOrderDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="tbxDetailOrderDate"> </cc1:CalendarExtender> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="tbxDetailOrderDate" runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' /> <cc1:CalendarExtender ID="tbxOrderDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="tbxDetailOrderDate"> </cc1:CalendarExtender> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="lblOrderDate" runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' /> </ItemTemplate> </asp:TemplateField> .......In the DropDownList SelectedIndexChange I do the relative calculations to figure out what I want the data to be, and then do this
((TextBox)dvOrderEdit.FindControl("tbxDetailRoastDate")).Text = String.Format("{0:d}",_dtNextRoastDay);
((TextBox)dvOrderEdit.FindControl("tbxRequiredByDate")).Text = String.Format("{0:d}",_dtDelivery);
But the data does not get updated. I have a terrible feeling I have to popular Session variable and then use some sort of bind. However I am not even sure how to do that.
What is the typical way of doing this?
mth13
Member
331 Points
96 Posts
Re: Data does not update in DetailsView
May 17, 2012 05:04 PM|LINK
Are you re-binding the detailsview after you update it?
Warren Macha...
Member
65 Points
50 Posts
Re: Data does not update in DetailsView
May 17, 2012 07:46 PM|LINK
As in:
dvOrderEdit.DataBind();
Yes, but still nothing, it was not there but I added it still does not work. Is there something before the bind?
superguppie
All-Star
48225 Points
8679 Posts
Re: Data does not update in DetailsView
May 21, 2012 12:16 PM|LINK
DataBind will overwrite things. So better not do that when you want to set data depending on DropDownList.
Have you used the debugger to check if the right data goes to the right TextBoxes?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Warren Macha...
Member
65 Points
50 Posts
Re: Data does not update in DetailsView
May 21, 2012 05:44 PM|LINK
Sorry for the late reply I had not got a notification. The data is there but explain how I check if the textboxes have been updated ?
I have sicne converted this system code to Access since we are sharing a database with the .net system, and the access system is working.
Here is the code for the complete dropdownlist event.
// defined at the top of the class const string DV_CONTROL_CUSTOMER = "ddlCustomer"; const string DV_CONTROL_ORDER_DATE = "tbxDetailOrderDate"; const string DV_CONTROL_ROAST_DATE = "tbxDetailRoastDate"; const string DV_CONTROL_REQUIRED_BY_DATE = "tbxRequiredByDate"; const string DV_CONTROL_QTY = "tbxQuantity"; const string DV_CONTROL_ITEMDESC = "ddlItemDesc"; const string DV_CONTROL_DELIVERY_BY = "ddlDeliveryBy"; const string DV_CONTROL_CONFIRMED = "cbxConfirmed";protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e) { // use the current customer and using their city get the next roast date for that city TrackerDotNet.classes.TrackerTools tt = new classes.TrackerTools(); DropDownList _ddlCustomers = (DropDownList)sender; // roast day vars DateTime _dtNextRoastDay; DateTime _dtDelivery = DateTime.Now; // preference vars; Int64 _CustID = Convert.ToInt64(_ddlCustomers.SelectedValue); int _preferredDlvryBy = 1; int _preferredItem = 1; double _preferredQty = 1; // get the next preparation date _dtNextRoastDay = tt.GetNextRoastDateByCustomerID(_CustID, ref _dtDelivery); tt.RetrieveCustomerPrefs(_CustID, ref _preferredDlvryBy, ref _preferredItem, ref _preferredQty); ((TextBox)dvOrderEdit.FindControl(DV_CONTROL_ROAST_DATE)).Text = String.Format("{0:d}",_dtNextRoastDay); ((TextBox)dvOrderEdit.FindControl(DV_CONTROL_REQUIRED_BY_DATE)).Text = String.Format("{0:d}",_dtDelivery); ((DropDownList)dvOrderEdit.FindControl(DV_CONTROL_DELIVERY_BY)).SelectedValue = _preferredDlvryBy.ToString(); (DropDownList)dvOrderEdit.FindControl(DV_CONTROL_ITEMDESC)).SelectedValue = _preferredItem.ToString(); ((TextBox)dvOrderEdit.FindControl(DV_CONTROL_QTY)).Text = String.Format("{0:N}", _preferredQty); /// dvOrderEdit.DataBind(); }Warren Macha...
Member
65 Points
50 Posts
Re: Data does not update in DetailsView
May 21, 2012 05:59 PM|LINK
Just did a watch on the items:
The cop paste from the wat screen:
((TextBox)dvOrderEdit.FindControl("tbxDetailRoastDate")).Text "2012/05/22" string
String.Format("{0:d}",_dtNextRoastDay) "2012/05/22" string
((TextBox)dvOrderEdit.FindControl("tbxQuantity")).Text "1.00" string
String.Format("{0:N}", _preferredQty) "1.00" string
But still no values in the detail view
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Data does not update in DetailsView
May 22, 2012 08:00 AM|LINK
Hi,
Handle the DataBound event of DetailsView to set these values to TextBox. Make sure the currentmode of DetailsView is in the edit or other mode you want.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Warren Macha...
Member
65 Points
50 Posts
Re: Data does not update in DetailsView
May 22, 2012 10:08 AM|LINK
Does that mean I need to store the data in a session variable? If not where will I get the data from?
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Data does not update in DetailsView
May 23, 2012 01:21 AM|LINK
Hi,
Using Session is a way. Or you can generate the data in DataBound event directly by using the SelectedValue from ddl.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Warren Macha...
Member
65 Points
50 Posts
Re: Data does not update in DetailsView
May 23, 2012 03:51 PM|LINK
so in the dropdownlist.selectvalue change I do nothing, but in the Databound even I check if the value has changed and then do the manipluation.
Sounds a bit arse about face, but I supposed a hacker has to do what a hacker has to do ;)