Problem:
This is a very common thing we all do. Ask the user to enter a date or a range of dates into a web form. The best way to ensure the format is to use the calendar control that comes with the ASP.NET framework. But these calendar controls are so huge that you'd only want to bring in to the page only when it is needed. There are many solutions offered on various web sites about how this is done.
The problem in most of the solution, at least for me, is that you need to understand or deal with JavaScript to open another window, pass some parameters to it, pass back more parameters and then finally to fill out the main form.
Many of us do not do web programming day in and day out and rather not have to deal with JavaScript (for that matter avoid any programming languages that start with a letter "J"). While he JS technique is definitely more elegant, we can hit the middle ground.
Solution:
One alternate solution that I came up with to take advantage of MultiView control. It is actually quite neat that you can basically create "layers" of panels that they call a View and expose any panel at your will. So for example in my case, I display a grid list of all previous surf stuff orders from past 30 days. When I need to ask for the date range, I have two calendar controls on another view asking for the first and last days, and I will bring that "forward." As soon as the second calendar control (for the last day) is clicked, I can trap the event for the Selected Date Changed, collect the new pair of dates from the controls, bring the view with the data grid again.
It is quite easy to do, just set whichever the view you would like to show in the MultiView control, and I did not touch a line of HTTP source code to do this.
Time Took To Figure Out
Once I've realized this possibility, it took me just about 30 min to confirm that this will work for me.
Answers to Software Questions the Experts Would Not Answer. Microsoft.NET, Java, Spring, Hibernate, JavaScript, C#, SQL Server as well as Mac, Solaris, Linux, CISCO IOS and related now include some Automotive IT! You could be having the same problem for hours like me!
Saturday, December 08, 2007
Friday, December 07, 2007
ASP.NET GridView Prevent Automatic Binding Upon Page Startup
Problem:
I have set up the ObjectDataSource from the Table Adapter using the Visual Studio 2005 in Design Mode. Now the page comes up fine, but I now want to add some query parameter filed, and do not want to show the grid right when the page comes up.
Fix:
There may be many ways of fixing it, but so far this technique is working well for me.
protected void ObjectDataSourceQuives_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e)
{
if (quiversEnabled == false) e.Cancel = true;
}
At another point in the code, for example, when the button to query a new quiver is pressed then I would set quiversGridEnabled to true, then subsequent calls to Bind() to the Gridview will show the data based on the query.
Time To Find The Solution:
It took about an hour to find out how I'd do this. If there are better and cleaner ways of doing it, be sure to comment on this entry.
I have set up the ObjectDataSource from the Table Adapter using the Visual Studio 2005 in Design Mode. Now the page comes up fine, but I now want to add some query parameter filed, and do not want to show the grid right when the page comes up.
Fix:
There may be many ways of fixing it, but so far this technique is working well for me.
- Go to the ObjectDataSource's property and switch to the Events view (the lightening bolt icon on top).
- Double click in Selecting event so that the VS will create an event handler.
- Go to the event handler.
protected void ObjectDataSourceQuives_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e)
{
if (quiversEnabled == false) e.Cancel = true;
}
At another point in the code, for example, when the button to query a new quiver is pressed then I would set quiversGridEnabled to true, then subsequent calls to Bind() to the Gridview will show the data based on the query.
Time To Find The Solution:
It took about an hour to find out how I'd do this. If there are better and cleaner ways of doing it, be sure to comment on this entry.
Sunday, December 02, 2007
SQL 2005 Find Out Who Are Connected
Problem:
I want to provide a list of currently connected SQL clients on my asp.net based web page, like the version of Activity Monitor that comes in the SQL Management Studio.
Solution:
The information are in the following queriable objects. For me, sp_who is good enough as I just need to list who are connected in my application monitor web app.
and finally this is supposed to give you the same list as what you see in the Activity Monitor (I did not try).
DECLARE @CMD VARCHAR(8000) DECLARE @ID int
SET @ID = @@SPID SET @CMD = '
EXEC sp_MSset_current_activity ' + CAST(@id as varchar) + '
SELECT * FROM ##lockinfo' + CAST(@id as varchar) + '
SELECT * FROM ##procinfo' + CAST(@id as varchar)
EXEC (@CMD)
Time Saved:
This information is either too obvious to DBAs or such that query to Google or Live does not provide an immediate answer. Took me about 30 min to finally found out. The keyword to search is "Activity Monitor"
I want to provide a list of currently connected SQL clients on my asp.net based web page, like the version of Activity Monitor that comes in the SQL Management Studio.
Solution:
The information are in the following queriable objects. For me, sp_who is good enough as I just need to list who are connected in my application monitor web app.
- exec sp_who
- exec sp_who2
- select * from master..sysprocesses
and finally this is supposed to give you the same list as what you see in the Activity Monitor (I did not try).
DECLARE @CMD VARCHAR(8000) DECLARE @ID int
SET @ID = @@SPID SET @CMD = '
EXEC sp_MSset_current_activity ' + CAST(@id as varchar) + '
SELECT * FROM ##lockinfo' + CAST(@id as varchar) + '
SELECT * FROM ##procinfo' + CAST(@id as varchar)
EXEC (@CMD)
Time Saved:
This information is either too obvious to DBAs or such that query to Google or Live does not provide an immediate answer. Took me about 30 min to finally found out. The keyword to search is "Activity Monitor"
Subscribe to:
Posts (Atom)