I have the following scenario I would like to implement.
I have a number of drop downs that the client can select a range of criteria. From this, they will press a button, the query will be generated and low and behold, a gridview will be produced in a new window (or at least give that impression) bound by an object datasource. I would also like the user to be able to amend the search numerous times so they can generate a number of new windows/gridviews.
Now then..what would be the best approach for achieving this result?
My initial thinking was to create a querystring generated by the client criteria selections (in the drop down lists), a new page would then take the querystring and populate the gridview here. My concern with this approach is that the query string could be a whopper...are there any disadvantages to creating a ridiculously long query string?
Alternatively, are there any other methods or ideas people have used to produce a similar desired effect?
Any suggests taken on board and all advice warmly received.
There is nothing wrong with a long querystring; it is just not as clean or as easy to use as Jeroen's session-object solution. Save the session object value:
Session("ObjectName") = variablename
Retrieve it:
variablename = Session("ObjectName")
The only reason to use a querystring is if you don't want the session data hanging around, though I can't imagine why that would be an issue.
You could handle the button's Click event and store the variables you need in Session object.
In the newly opened window with your gridview you take those values and assign them to the proper parameters in your ObjectDataSource's Selecting event.
Related
I'm trying add multiple items to a database table. I've created a form that will allow the user to add more form rows which include a dropdown and multiple input fields. New fields are generated when the user clicks on "+". This is developed using JavaScript.
It is easy to add an incremented value to an ID using JavaScript, but new rows are not made using the runat="server" so I am afraid my code behind won't see the values in the fields.
I want my code to loop through each form "row" and grab each item. Then take this data and insert it into a SQL database. How do I get that working?
I can give you some guides to continue from the point you are (and solve this question - so I am afraid my code behind won't see the values in the fields.)
a. You create your controls using java-script on the page.
b. User then is post them back, what you have all ready known, with some new controls that code behind didn't know about.
now the trick here is that you grab this return
HttpContext.Current.Request.Form
and analyse it to see whats "is new there", what are the new post controls that you don't know about - and then you create them on code behind again - and gets their input values.
I am making a basic ticketing system in C# with basic coding experience. Most of my experience is in SQL.
I have the database and tables. I have stored procedures to create and amend tickets.
I am stuck (this is probably very basic) because:
On my EDIT ticket page, I populate various text boxes and drop downs from my existing data via inline SQL.
On my page, I can edit all the fields and dropdowns with new values. (i.e. change a ticket priority from when it was first logged)
I have a button, that calls my "update" stored procedure, however it updates only the NEW fields I have, any amendments to the existing fields are overwritten by the original values before submitting.
The original values are called on pageload, so I think the button reloads the page before submitting. I want it to submit all the values that are on the screen.
I think this must be something obvious, remember I am a novice so I may have missed something simple.
If what you're saying is you load values from the DB into the form controls in the PageLoad event handler, then yes, you're probably overwriting the changed values. To keep things as simple as possible for you, wrap the original values loading code in the following:
if( !IsPostBack )
{
// load initial form values here from DB
}
I'd suggest you read about the ASP.NET page lifecycle: http://msdn.microsoft.com/en-us/library/ms178472(v=vs.90).aspx
I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.
I am showing some information on mouse hovering on the links. I am doing this by making an AJAX call on mouse hover the the links and fetching the data from database.
Problem is that if I mouse hover several times on the same link it will make the AJAX call and hit the database in each time. But I want if it once fetch the data from the database for a specific link on second time mouse hover it should not hit the database again. For this I need to store the data in client side some where and reuse it(I think).
What is the best approach to handle this situation? Can any one suggest me the solutions?
P.S: I am having more than 20 such links in the page.
use the One function, it guarantees that the call gets executed once.
You could store the information in a hidden field or fields. On the first request, just check if the requested info is already available in there, and if not, hit the database.
May this will be a wrong way but you can do this in this way:
Define class attribute for the anchor tag and change the class to true to false after loading data from database when someone click this link again check the class name what it indicates true or false in this way you can do
<a class="load-true"></a>
after loading data
<a class="load-false"></a>
and check class to load data.
thanks
on the JavaScript side, use a hash table where the keys correspond to the IDs of links that have been hovered. You only call the DB when inserting a new key (as in allHovers[curHover]++; ) A side benefit of this is that you would have a list & count of hovers that you can reference at any time.
I'm creating a web form, where in there are around 12-15 Input Fields...
You can have a look at the screen here http://img9.imageshack.us/img9/2951/image001um.jpg and here http://www.freeimagehosting.net/uploads/f9f4491598.jpg
The request is such that depending on the data the user selects in the Gridview and the DropDown list, the appropriate Textboxes and CheckBoxes needs to be displayed.
Some times the conditions are very direct, like when the DDL value is "ABC", get only paid amount from the user.
Sometime they are so complex like... IF DDL is "DEF" and Selected GPMS value is between 1000-2000, calculate the values of allowed, paid etc (using some formula) and the focus should be directed to Page No Field, leaving the other fields open incase user wants to edit... There are around 10-15 conditions like this.
As this was done through agile, conditions were being added as and when, and wherever it feels appropriate (DDL on change Event, GridView on selecting change event etc... etc..) After completion, now I see the code has become a big chuck, is growing unmanageably...
Now, I'm planning to clear this... From you experience, what you think is the best way to handle this. There is a possibility to add more conditions like this in future...
Please let me know, incase you need more information. I'm currently developing this app in C# .Net WindowsForms
Edit: Currently there are only three items (The Datagrid, the DDL, the OverrideAmt CheckBox) that change the way other fields behave...
Almost all of the conditions will fall between the two situations I mentioned...
Mostly they belong to "Enabling/Disabling".. "Setting of Values"... and "Changing Focus"
or any combination of these.
Minimal overhead
Write a single-procedure that contains all the evaluation logic.
i.e. evaluate all the individual states and show/hide the appropriate controls from within the procedure.
Now call this procedure whenever there is any change event
that requires you to re-evaluate whether to show/hide any controls.
Do NOT show/hide any controls from outside this procedure.
Any additional validation-checks in future can always be easily incorporated
by adding the additional checks inside this procedure.
To improve upon the performance of this procedure:
[1] Add a parameter (int/string) to the procedure.
[2] Pass a different value in this parameter when calling from different events of different objects.
[3] In the procedure, from on the value of the parameter, you can determine what object(& what event) has triggered this re-evaluation.
Thus You can evaluate only those conditions that could possibly depend on this particular change in this particular object. This way the re-evaluation overhead is reduced to the bare-minimum.