Friday 15 July 2011

c# - Can you call PadLeft inside a databound server control? -


Say I have a label inside a gridview template column and I place the text on the databound item, "order-end". Is there a way I can call? Toaster (). Pad left (7, '0')? In the form of a label it stands:

  & lt; Asp: Label ID = "lblOrderID" runat = "server" text = '& lt;% #' WW '+ DataBinder.Eval (container.datetime), "order id")% & gt; '/ & Gt; 

PaddleFit requires four axes, I can not use my single quote because I already surround the value in a quote and do not double quote due to the databinker can. Aval expression Is there another way that I can work it on one line?

You can inline (I 'I will leave it for someone else because I can answer it For VS is not open).

But I call it a formatted order ID by adding a method to codebihind. Or better, the format method is put in a stable helper square, so it is available on a page that requires a formatted order ID.

If you are bound in the collection of orders, then something like this:

  public stable string GetFormattedOrderId (object datagram) {order order = (order) dataItem; Return String.Format ("WW {0: N7}", order.OrderId); \ // Or order back. OrderAud. ToString (). Pad Left ... if you want  

or if you are bound to datatable, then something like this:

  Public Stabilized String GetFormattedOrderId (Object Datagram ) {DataRow row = (DataRow) dataItem; Return String.Format ("WW {0: N7}", line ["OrderId"]); }  

Then you can have formatted order ID in any of your markups:

  '<% # myFormattingHelper.GetFormattedOrderId (container. Data format)% & gt; ' 

No comments:

Post a Comment