<%# Bind([ReqPo!ItemId])%> doesnt work - asp.net

In Dynamics ax Enterprise Portal I have created a templatefield in AxGridView. Seems everything ok, but when i try to enter some value to this textbox (manually or through lookup), it doesnt bind to ReqPo!ItemId field. Checked that with info(strfmt("%1", ReqPo.ItemId))); in validateWrite method on ReqPo dataset - it prints nothing; What i'm missing?
<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="<%$ AxLabel:#SYS12836 %>" Visible="true">
<EditItemTemplate>
<asp:TextBox runat="server" ID="TextBoxFilterItemId" CssClass="AxInputField"
Columns="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.DisplayLength %>"
Enabled="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.AllowEdit %>"
MaxLength="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.StringSize %>"
Text='<%# Bind("[ReqPo!ItemId]") %>'>
</asp:TextBox>
<dynamics:AxLookup
ID="AxLookup3" runat="server" OnLookup="Item_lookup" TargetControlId="TextBoxFilterItemId"
CssClass="AxLookupButtonBF" HoverCssClass="AxLookupButtonHoverBF" ShowFilter="True">
</dynamics:AxLookup>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ItemIdLabel" runat="server" Text='<%# Bind("[ReqPo!ItemId]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

I assume you are using the ItemId field from the table ReqPo. If you locate that field in the Data Dictionary you will discover that the field does not allow editing.
As AxGridView only supports editing, which leads me to the conclusion that you are trying the break the data integrity rules of the application.
if this is the case, it is obviously not possible.

Related

How to show current date in detailview asp.net automatically

I'm using asp.net and I'm creating a detail view from a database. The database I create got a column I want set auto show current when edit or insert like using timer like vb.net code
lblClock.Text = TimeOfDay
My Sample source from asp.net :
<asp:TemplateField HeaderText="Time Out" SortExpression="TIME_OUT">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("TIME_OUT") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("TIME_OUT") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("TIME_OUT") %>'></asp:Label>
</ItemTemplate>
What I want is when I click the edit button it will automatically show the current time and then I just click update.
try this..........TextBox1.Text = DateTime.Now.ToString("HH:mm");
In your Page Load event add this code
lblClock.Text = DateTime.Now.ToString();

add text after dataGrid cell

This is dataGrid . How to add text(string) after <%# Bind("Value") %>
for example 123.432 and i want after any record to have "$" dolar sign
<asp:TemplateField HeaderText="Стойност">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Value") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelValue" runat="server" Text='<%# Bind("Value") %>'>
</asp:Label>
</ItemTemplate>
<ControlStyle Width="100px" />
</asp:TemplateField>
<% String.Format("{0}$",Eval("Value")); %>
You can take benefit of Standard Numeric Format String
<asp:Label ID="LabelValue" runat="server"
text='<%# Bind("Value").ToString("C", CultureInfo.CurrentCulture) %>'/>
which is a standard format available with C#.
But you want to show it in the last then you can simply add it in the last.
<ItemTemplate>
<asp:Label ID="LabelValue" runat="server" Text='<%# Bind("Value") %>'>
</asp:Label>
$
</ItemTemplate>
I suggest you to use MaskedEdit extender in ajax toolkit if you already using ajax toolkit in your project. MaskedEdit extender can be use in edit template and it will handle the mask on client side you don't want to worry about value and $ sign when you read the value back.
without using ajax toolkit you can use one label for $ sign and textbox for value field on edit template. In normal template also use two labels for both value and $ sign. then it will be easy to read the values.

Displaying hours and minutes from a SQL Server time column in an ASP.Net DetailsView

In an ASP.Net DetailsView is a templete field called LateTimeArrivedAtSchool. The data for this field is from a SQL Server Time column. The data in the database in stored as hours, minutes and seconds.
We would like to display it as only hours and minutes.
Here is the markup for the template field:
<asp:TemplateField HeaderText="Late Time Arrived At School:" SortExpression="LateTimeArrivedAtSchool">
<EditItemTemplate>
<asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelLateTimeArrivedAtSchool" runat="server"
Text='<%# Bind("LateTimeArrivedAtSchool", "{0:hh:mm}") %>'></asp:Label>
</ItemTemplate>
<ItemStyle ForeColor="Blue" />
</asp:TemplateField>
using "{0:hh:mm}" produces an error that states the "Input string was not in a correct format."
Can you tell me what we need to use in the Bind statement?
* UPDATE *
I changed the SQL Server data type of the column from a Time column to a DateTime column and was able to display the time only portion of the data.
Use eval instead of bind
Text='<%# string.Format("{0:hh:mm}", Eval("LateTimeArrivedAtSchool")) %>'

DetailsView converts TextBoxes empty string to null

I have a basic ASP.NET Web Forms application.
I give the user the possibility to create the records by using a Web Form and to update them by using a DetailsView.
The web form stores the empty field on the TextBoxes as *empty strin*g in the DB correctly.
The DetailsView instead stores them as null fields in the DB.
Moreover in the DetailsView_ItemUpdated event if I check the e.newvalues and e.oldvalues arguments the corresponding fields are null as well (throwing an exception) that means the data are already sent as null to the server upon submit.
In the DetailsView I use templates and I set all Update parameters in the SQLDataSource as ConvertEmptyStringToNull="false".
SQLDataSource parameter:
<asp:Parameter Name="SHELF" Type="String" ConvertEmptyStringToNull="false"/>
DetailsView
<asp:DetailsView runat="server"
ID="GvProductDetail" AutoGenerateRows="False" DataKeyNames="rowid"
DataSourceID="ProductDetailData"
OnItemUpdated="gvProductDetail_ItemUpdated">
<asp:TemplateField>
<HeaderTemplate>Stock Shelf </HeaderTemplate>
<ItemTemplate>
<%# Eval("Shelf") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtShelf" Text='<%# Bind("Shelf") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
Is that possible that Bind converts the empty values to null? I thought it was enough to set the UpdateParameters rule not to convert empty string to null but apprently there is some other surprise. anybody might help?
I solved it by placing ConvertEmptyStringToNull="false" to every <asp:TemplateField> containing <asp:TextBox>:
<asp:TemplateField ConvertEmptyStringToNull="false">
<HeaderTemplate>Stock Shelf </HeaderTemplate>
<ItemTemplate> <%# Eval("Shelf") %></ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtShelf" Text='<%# Bind("Shelf") %>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

Databinding Error when Recreating object

Figure there is a simple solution to this problem but I have been unable to find it.
I have databinding in an ASP.Net application to a GridView. This gridview is bound to an ObjectDataSource as per standard usage.
The problem I have is that one of my bound fields uses the property DataFormatString="{0:C}" and due to the currency format being displayed when an update is attempted and the object recreated I get a error as such "$13.00 is not a valid value for Decimal."
Clearly this is a result of the column using a FormatString and then attempting to bind it back to a decimal property I have in my object called UnitPrice.
I am assuming there is some markup I can set that can specify how the value is translated back?
Thanks in advance for any help.
For anyone curious the solution ended up looking like this...
<asp:TemplateField>
<HeaderTemplate>
UnitPrice
</HeaderTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditItem" runat="server" Text='<%# Bind("UnitPrice", "{0:#,##0.00}") %>' Enabled="false" ></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("UnitPrice", "{0:c}") %>' ID="lblUnitPrice"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Do not include the format string in the EditItemTemplate. Just bind the raw value.
Something like this:
<asp:TemplateField SortExpression="UnitPrice" HeaderText="Unit Price">
<EditItemTemplate>
<asp:TextBox ID="editUnitPrice" Runat="server" Text='<%# Bind("UnitPrice", "{0:#,##0.00}") %>' ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("UnitPrice", "{0:c}") %>' ID="Label1"> </asp:Label>
</ItemTemplate>
</asp:TemplateField>

Resources