Monday, November 16, 2009
#
This trick might work if you have an application that has been moved from the 2.0 framework to 3.5. This happened to me recently and I had tried removing the Web.Extensions reference and adding it back in, deleting old pages that had the older ScriptManager on them and manually removing then adding back the Web.Extensions sections in the web.config file. Nothing worked so I compared the web.config files from the problem project to one that was created from scratch targeting the 3.5 framework.
I saw that on the updated project the <configuration> tag looked like:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
where the fresh project was just <configuration>. Once I removed the xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0 the project would compile and run again.
Technorati Tags:
AJAX,
ASP.Net
Friday, November 13, 2009
#
Here is a really quick CSS item to apply styles to different types of textboxes in an ASP.Net application. A plain old vanilla asp:textbox control will show as an Input if you view the source of the page. To set the styles of all those controls from a css file you can add this to your css:
input[type=”text”]
{
font-size: 8pt;
font-family: Arial;
}
Then you do not need to add the CssClass property to the textboxes in the aspx file. The input section of the css will be applied automatically. This saves some time and you only need to change the styles in one place. However if you have a textbox with the TextMode property set they will not render as an Input but rather as a Textarea. So to set all those types of asp:textboxes in your css file just add the following to you css file:
textarea
{
font-size: 8pt;
font-family: Arial;
}
After that both “types” of textboxes should have the same font size and family.
NOTE: See the first comment. Using input[type=”text”] will work for compliant browsers to prevent the style from being applied to other input types like buttons, checkboxes, radio, etc.
Technorati Tags:
ASP.Net,
CSS
Friday, November 06, 2009
#
Here is an easy way to find duplicate data in a table. This simple example would return any userNames that appear twice or more in the table.
SELECT userName, COUNT(userName) as UserDup
FROM tblUsers
GROUP BY userName
HAVING Count(userName) >= 2
I find this handy to use when users need to know how many times a certain item appears but there is no way to sort that data in their application or there is no report written for them to use. It is also a useful check when migrating data over from an older Access application that has been around for years to SQL Server. Frequently the Access application may not have checks for duplicates and over time (and many different users) several records for the same item may have been entered by mistake.
Friday, October 30, 2009
#
Adding a new row to a datatable in a specific position is a snap. The scenario in this case would be that you have a datatable filled via a stored procedure that is also used in other applications so it can not be altered. The datatable is used to populate a dropdownlist and that list needs to have the always popular ‘Select All’ option as the first item. To add this in you could use code like what is listed below after the datatable is populated from the stored procedure. The example uses two columns in the datatable, ‘DropDownValue’ and ‘ReportItem’ and dt is the already declared DataTable.
VB.Net
Dim allRow as DataRow = dt.NewRow
allRow(“DropDownValue”) = 0
allRow(“ReportItem”) = “Select All”
dt.Rows.InsertAt(allRow, 0)
C#
DataRow allRow = dt.NewRow;
allRow("DropDownValue") = 0;
allRow("ReportItem") = "Select All";
dt.Rows.InsertAt(allRow, 0);
The main part to look at is InsertAt. This allows you to enter in the row you created at the position you need (the first row in the example).
Technorati Tags:
VB.Net,
CSharp
Friday, October 02, 2009
#
Every now and again you may come across an error when trying to update a database from a data driven control (i.e. gridview, formview) that is tied to a SQL or Object data source. The errors usually are along the lines of “Could not find xxx that has parameters” along with a list of those parameters. Or an error that states there are too many parameters being passed. Aside from looking for typos, counting or lining up the parameters I will use one of these techniques to try and narrow down what may be the issue. By placing a breakpoint at the i+=1 line and stepping through the loop often times I will see the problem. The code would go in their respective type’s updating method.
VB
SQL Data Source
Dim cmdParams As System.Data.Common.DbParameterCollection = e.Command.Parameters
Dim paramName As String
Dim paramValue As String
Dim i As Integer = 0
While i < cmdParams.Count
paramName = cmdParams.Item(i).ToString
paramValue = cmdParams.Item(i).Value.ToString
i += 1
End While
Object Data Source
Dim paramName As String
Dim paramValue As String
Dim i As Integer
While i < e.InputParameters.Count
paramName = e.InputParameters.Keys(i).ToString
paramValue = e.InputParameters.Item(i).ToString
i += 1
End While
C#
SQL Data Source
System.Data.Common.DbParameterCollection cmdParams = e.Command.Parameters;
string paramName;
string paramValue;
int i = 0;
while (i < cmdParams.Count) {
paramName = cmdParams.Item(i).ToString;
paramValue = cmdParams.Item(i).Value.ToString;
i += 1;
}
Object Data Source
string paramName;
string paramValue;
int i = 0;
while (i < e.InputParameters.Count) {
paramName = e.InputParameters.Keys(i).ToString;
paramValue = e.InputParameters.Item(i).ToString;
i += 1;
}
Technorati Tags:
VB.Net,
CSharp,
SQL
Wednesday, September 30, 2009
#
I had posted this last month and saw a comment posted quickly that you can use CSS as well. A way to use CSS is listed below.
<table style="float: left; width: 300px; margin-left: 15px">
</table>
<table style="float: right; width: 500px; margin-right: 15px" >
</table>
Technorati Tags:
HTML,
ASP.Net
Wednesday, August 12, 2009
#
Here is a long time issue and this is by no way the first post about it (or probably even the 1000th). In the code below I have two tables that needed to be side by side. The first one on the left allows a user to search for site notes. Just a few dates and a note type. The second table allows a user to enter a new note. Even less to enter just a date and the text for the note. Since I needed the tables side by side I nested both into one big table, keeping each table in it’s own cell and both cells on the same row of the big table. That worked fine but the search table on the left was centered vertically and the add note table started at the top like I expected. But it did not look quite right. To get both tables to start on the same line at the top I added valign=”top” to the cell of the left search table. That forces the table to the top.
<table>
<tr>
<td valign="top" >
<table >
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Search Notes" CssClass="tableLabel"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtNoteStartDate" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtNoteEndDate" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddlNoteType" runat="server" DataSourceID="odsNoteTypes" DataTextField="ItemName" DataValueField="AppValue" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnNoteSearch" runat="server" Text="Search" />
</td>
</tr>
</table>
</td>
<td>
<table >
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Add Note" CssClass="tableLabel"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtNoteDate" runat="server" />
</td>
</tr>
<tr>
<td >
<asp:TextBox ID="txtNote" runat="server" Width="500px" TextMode="MultiLine" Rows="7" />
</td>
</tr>
<tr >
<td >
<asp:Button ID="btnAddNote" runat="server" text="Add Note" />
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
Technorati Tags:
HTML,
ASP.Net
Thursday, July 16, 2009
#
Passing nulls and blank values to SSRS via an URL requires a very little bit of work. For a null value you first need to call up the Report Properties (in the Layout tab select the entire report and click on Properties on the right) in SSRS and click on the button in ReportParameters. Once the Report Parameters window has opened you can set the parameter to allow nulls by checking the ‘Allow null value’ box. Then from the application that runs the report use Parameter:isNull=True in your URL if you need to pass a Null value.
For a blank value call up the Report Parameters window again and check the ‘Allow blank value’ checkbox for the parameter(s) you need to be able to pass a blank value to. In your URL you can then use Parameter= to pass nothing. Here is an example URL with the Date parameter using Null, PlayerID with a blank value and Sport using a value:
&Date:isNull=True&PlayerID=&Sport=Soccer
Monday, July 13, 2009
#
This is a completely non-dev related post, but something that had been really getting under my skin for about a month now. I have one Vista PC and it always turned of the monitor like it should. Then it just stopped working. I looked around a bit off and on, since it wasn’t a huge deal I didn’t look that hard. But I had some time the other day and found a super easy fix.
I have the power configuration set to run the screen saver after 10 minutes and then turn off the monitor after 20 minutes. The screen saver would run the picture slide show. That ended up being the issue. When the folder the pictures were in had more than 50 pictures (I had 54) the screen saver would never stop running and the monitor would never go to sleep. I moved about 20 pictures to a totally different folder and like magic the screen saver would stop and the monitor would go to sleep.
A far more detailed posting can be found here: http://www.vistaheads.com/forums/windows-vista-home-premium/192323-vista-display-wont-turn-off.html and many thanks to ulysseus123 for figuring it out.
Wednesday, June 24, 2009
#
This is one way to have up/down or open/close arrows appear on an AJAX AccordionPane. First add a div and an img to the Header of the AccordionPane along with the title (the example uses ‘Add Widget’).
<cc1:AccordionPane ID="apTest" runat="server" >
<Header>
<div id="div1" onclick="UpDownIcons('imgAcc')">
Add Widget <img src="Images/arrow_down.ico" id="imgAcc" alt="expand" />
</div>
</Header>
Note the onclick function for the div, that is where the change takes place. Here is the code for the ‘UpDownIcons’ javascript function.
function UpDownIcons(paneImg)
{
var clicked = document.getElementById(paneImg);
var currentIcon;
currentIcon = clicked.src.endsWith('arrow_down.png');
if(currentIcon)
clicked.src='App_Themes/MainTheme/Images/arrow_up.png';
else
clicked.src='App_Themes/MainTheme/Images/arrow_down.png';
var others = document.getElementsByTagName('img');
for(i=0; i<others.length; i++)
{
if(others[i].id!=clicked.id)
others[i].src = 'App_Themes/MainTheme/Images/arrow_down.png';
}
}
The first section of the script is necessary to flip the arrow when a user clicks on the same accordion to close it rather than a different accordion. The loop runs through the other imgs to switch their src.
You would need to change the img src to your image path and you would need to change the ‘arrow_down.ico’ in the currentIcon=img.src.endsWith line to match your icon names. Also this example assumes that this pane would be closed to begin with so the default src is the down arrow icon.