String Formatting question

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

I have a string being returned to my in my ascx file. I get access to it like this... <%# DataBinder.Eval(Container.DataItem, "RoomNumber") %>. This is pretty simple. I want to be able to take the value of "RoomNumber" and do a substring on it. So if RoomNumber returns "A1234," I want to be able to get "A" or "4" from this return value. How can I do this in C# inline in my ascx?

I know I can use <%= %> and <%# %>, but I am not clear on which ones to use at which occassions. I think I would need something to return "RoomNumber" followed by a .Substring(1,1) or something. Can anyone suggest something?

Thanks,

Alex
 
Nevermind, I figured this out after I sent the question, of course. I solved it like this...

<%# DataBinder.Eval(Container.DataItem, "RoomNumber").ToString().Substring(1,3) %>

--
Alex
I have a string being returned to my in my ascx file. I get access to it like this... <%# DataBinder.Eval(Container.DataItem, "RoomNumber") %>. This is pretty simple. I want to be able to take the value of "RoomNumber" and do a substring on it. So if RoomNumber returns "A1234," I want to be able to get "A" or "4" from this return value. How can I do this in C# inline in my ascx?

I know I can use <%= %> and <%# %>, but I am not clear on which ones to use at which occassions. I think I would need something to return "RoomNumber" followed by a .Substring(1,1) or something. Can anyone suggest something?

Thanks,

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top