Get data from an SQLDataSource to a DataTable and Bind Grid

This week, I needed to bind a gridview to and SQLDataSource. The only problem is that I need to include extra rows. How to do this? First I removed the binding code to bind the grid directly from HTML (in gridview remove the DataSourceID attribute).

Then I wanted to get the data from the SQL Data source and convert to a data table to insert and update the table as needed. Next is the code to get the data… Continue reading

SQL Server | Reset Identity Column

When you create a table in SQL Server, you would also have an Identity Primary Key. This type of key would increase as new rows are added. But sometimes you would just need to delete all the rows and start all over again.

To restart the identity column, you could delete the column and re-add it again. This would normally work, but if you have relations with the primary key, you wouldn’t be allowed to delete it.

The next code that will make this possible, and restart the Primary Key from 0, thus the new row will be set as 1: Continue reading

ASP.Net 4.0 Validate Request

When creating a CMS sometimes you need to allow certain tags pass through the ASP.Net Validation. To allow tags be posted, in v2.0, you had to include the following tag in the page directive:

ValidateRequest="false"

But in .Net 4.0, this is not enough. You also need to include the next tag (httpRuntime) in the web.config file under <system.web>:

<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0" />
</system.web>

There is also other information on Error validation in .Net 4.0 here

Resources: here

Windows Phone 7 Development

Today I started researching and making some Windows Phone 7 apps. The development tools are all free. You just need to download the free tools from here and everything will install automatically.

The Tools

The Windows Phone tools are added to the Visual Studio 2010 IDE so you won’t find any problems starting using it. WP7 apps are developed using Silverlight for Windows Phone or XNA 4.0. Continue reading

ASP.Net | Read Values from Javascript

Today I started checking out some videos about Windows CardSpace and ASP.Net for logging in and I saw how he used javascript to get client side input and use it in ASP.Net in the C# code.

First you need to create a HiddenField on your webForm and name it TokenField (any name would actually do)

<asp:HiddenField ID=”TokenField” runat=”server” />

To set the Hidden Field value in JavaScript use the following code: Continue reading

Div OnClick instead of a href | Quickie

Instead of using the “<a href=” tag to go to another page, you can use the “<div onclick=” to be transferred to another page. This is extremely useful if you have a lot of text and pictures that need to be clicked anywhere wanted. Next is the html code to achieve this:

<div id="div_id" onclick="window.location = 'Your reference here'>
Your text here
</div>

Hope this Quickie was of help 😉