<%#Eval %> in asp.net to move page - html

Like other 'List' page, I'm making a <a> tag on td, and 3buttons 'Go up','Go down','Go list'.
I succeed after click this link, go another page.
<%#Eval("Title")%>
Now, the problem is here. To make Go up/down pages, I guess put the number +1 on the link to calculate page number.
<%#Eval("Title")%>
Then, when I check address, result just show +1 not calculate.
//address : http://localhost:61375/NoticeDetail.aspx?seq=+1
How can I calculate on Eval Databinding data and show that? or, do you know how to make a function up/down page with Eval?

If you have a string value in the database and you expect it to always be an integer and it shouldn't be null, then you should use int.Parse()
<%#Eval("Title")%>
Otherwise if you don't know the type of data and you don't sure about the null values then should use Convert.ToInt32(). Convert.ToInt32() returns 0 for null, while int.Parse() throws a ArgumentNullException
<%#Eval("Title")%>

You're not parsing the int, try this (if your int is nullable though, make sure you check for that first):
<a href='NoticeDetail.aspx?seq=<%# int.Parse(Eval("Seq").ToString()) + 1 %>'><%#Eval("Title")%></a>

Related

Need Validation on html dropdownlist with data from Viewbag

I know I'm not supposed to use the Viewbag and that I should build a menu using Html.DropDowlListFor() so that i can add attribute bound to the members of the model, BUT, that would involve a pretty extensive code rewrite....
I have a custom controller with a menu:
*.ASCX
<%: Html.DropDownList("CityIDs", new SelectList(ViewBag.cities, "Id", "Name"), "--Select--", new { style = "width:200px" })%>
<%= Html.ValidationMessage("CityIDs") %>
The List populates just fine and I can default to the top item to "--Select--"
The prbolem is that I want the validation error to occur on anything that is not from the viewbag.... how can I achieve this?
Validation for dropdown lists only ensures that something was posted. If you want to ensure that the value that was posted is actually one of a set of "allowed" values, then you'll have to manually do that in your post action:
var cityIds = db.Cities.Select(m => m.Id);
if (!cityIds.Contains(model.CityIDs))
{
ModelState.AddModelError("CityIDs", "You must select one of the available choices.");
}
if (ModelState.IsValid)
{
...
Two things:
Notice that I'm pulling the city ids straight from the database (the actual code you'd need here, of course, depends on your specific implementation). The important thing, though, is that ViewBag only survives a single request, so you can't look for them in ViewBag after posting.
Despite the pluralized name of CityIDs, using the DropDownList helper ensures that only a single selected value will exist. If this is actually supposed to be a multiselect, then you need to use ListBox instead, and update this conditional here to account for check for multiple values.
Populates the top item with Text = "--Select--" and Value = ""
which will post a blank value for CityIDs and cause an error in ModelState.

how to make next link for pagination

I am new to jsp in my jsp i have
href="${mainUrl}/userdata?page=1" target="_blank">Next On First Page
href="${mainUrl}/userdata?page=1" target="_blank">Next On 2nd Page
href="${mainUrl}/userdata?page=1" target="_blank">Next On 3rd Page
href="${mainUrl}/userdata?page=1" target="_blank">Next On 4rth Page
However , i want this link on every page
Requirement :
Next
So i applied for-each loop on tag
<c:forEach items="${i}" var="i">
Next
</c:forEach>
${i} : Its an attribute from my controller with int i=0;
However , compiler is saying it cant interate on "i"
How can i fix that? I am doing Pagination
Assuming userdata is your controller. Make the controller set the next page's id, not the current one's, and name it something better than i, like nextPageID.
So in the controller, take the current id received in the request parameter page, if any, and add one to it, and set it in the request attribute nextPageID. I guess if no page id was received, the next id would 2. Then in your JSP:
Next
Because if you are adding one in the JSP, how do you know this isn't the last page? Keep the logic part in the controller. The controller will presumably know which number is the last page.
BTW, you obviously cannot iterate on a simple int; Iteration means traversing over an array or list.

Rails view dependent on time

I'd like to have a div in my view, that shows a piece of text, if the current time is between 9am-5pm GMT, Monday-Friday. But a button if it's outside of that time.
How can I achieve this?
You have helpers for time and day like Time.now to get the current time and Time.now.wday that returns the integer corresponding the week day. Just compare then with your rule in your view and you are good to go.
Something like this should work
# Time.now.utc may work
now = Time.now.in_time_zone('GMT') as well
if time.wday.in?(1..5) && time.hour.in?(9..16)
# show text
else
# show button
Make sure you modify this code for the templating engine you use (ERB or HAML) appropriately.
In your controller, you can check something like #open = (1..4).include?(Time.now.wday) && (9..17).include?(Time.now.hour)
You get true, or false. Now, you are able to use #open to show the button (false), or the text (true)

Html5 localstorage between two pages

Am trying to make a game using Html5. my need is i have menu html page with 3 buttons one,two,three. when am clicking on that button am storing that value like one or two or three storing in a variable and it'll go to next page game.html. and i can retrieve it too.
localStorage.setItem("value",$(this).val()); //storing 1,2 or 3 in value
var value_menu = localStorage.getItem("value"); //getting value in value_menu
here i have a back button in game.html page, if i click on that it'll go to menu page and am removing the key values from localstorage.
localStorage.removeItem("value"); (or) localStorage.clear();
if am again click on the buttons in menu page, the value showing as null. why its showing as null ? because if i click on button the localstorage have to store value again. isn't it?
otherwise am making any mistakes? need some explanations.
thank u in advance.
Because null is the default value when something does not exist and you delete the value when yo go back so it is "logic" .... the value is null because it does not exist because you remove it.
Okay? ;-)
You can interpret null as 'not selected' (in your case it IS not selected and that's true because you have deleted it when the user go back). The next thing you have to do is to check if the value is null (value === null) and to do nothing when it is null (not showing it). Or much better: if( typeof value == "number" && value > 0 ) etc.
It think it is better to not remove the choice of the user until the user left the first/entry page.
Pure interest: What kind of game do you want to create?

Compound object in HTML <button> value attribute

If for some reason it were mandatory to associate a <button> with more than one value, is there a good way to do it? For example ...
CSV:
<button value="Lancelot,Grail,blue">Answer</button>
JSON:
<button value="{'name':'Lancelot','quest':'Grail','color':'blue'}">Answer</button>
In the absence of a good way to do it, is there a traditional way?
Edit: another use case
Server M, the producer of the HTML, knows the user's current location and favorite genres, movie names, nearest theater, and next showtime. Server F knows how to query various 3rd party servers about how to get from point A to point B in order to arrive by time T. The user knows only the movie names: click Drag Me to Hell, and get the route. Server M could generate a form for each movie, with a single button showing the name of the movie and multiple hidden fields with the start and end locations and desired arrive-by time, but that would require a lot of repeated code. Every one of these one-button mini-forms would have the same method and action and the same hidden input field structure. Styling would be a collection of mini-forms rather than a collection of buttons, so FIELDSET and LEGEND are unavailable (because HTML forbids nested forms). Putting the parameters into the button's value attribute would be much tidier.
Well if you have to have a button element, why not use JavaScript to set a bogus property:
$('mybutton').compoundValue = { ... json ... };
and then reading the 'compoundValue's during form submit, etc.
Though really you might want to consider a group of checkboxes or some other form bits for what you're trying to accomplish.