.NET

Error when trying to install full Visual Studio : You must uninstall all the pre-release products in a specific order before you can continue with setup

If you had been participating in the Beta program and once expired want to install the full 2008 you might come across this error. The dialog box will tell you which programs / components it wants you to delete before allowing you to install, however sometimes you won’t be able to find them in add/remove programs. Before you try what I originally did and delete nearly everything, most of which didn’t need to be deleted, try these steps:

1. Download msiinv.zip
2. Extract the contents of msiinv.zip to the folder c:\msiinv on your system
3. Click on the Start menu, choose Run, type cmd and click OK
4. Run c:\msiinv\msiinv.exe -p > c:\msiinv_output.txt
5. Open the msiinv_output.txt document and search for that damn program you hadn’t been able to find
6. Grab it’s program code which will look something like this: {90120000-0021-0000-0000-0000545446}
7. Open command prompt and run this line with your product code instead of the one I’ve used: Msiexec /x {90120000-0021-0000-0000-0000545446}
8. Repeat 6 & 7 for each of the programs you needed to uninstall
9. Run the VS 2008 installer again and you should be alright

If luck just isn’t going your way and it still isn’t working, try this link for further ideas:
http://blogs.msdn.com/varungupta/…..

Sorting Gridview (Get it working quick!)

There are lots of references out there for getting a sortable gridview up, however I feel each of them are missing certain bits of information which make them incomplete. I ended up having to use three different references before I could get mine working!

Firstly, the stuff you are here for, the complete code to get a sortable gridview up and working! Below the code are the details you may/may not want to be bothered with.

.aspx.cs file

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
private string _connectionString;
private SqlConnection _conn;
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvSortable.DataSource = getData();
gvSortable.DataBind();
}
}

private DataSet getData()
{
_connectionString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
_conn = new SqlConnection(_connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM tbl_user", _conn);

DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}

public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;

return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}

protected void sortGv(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression;

if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, DESCENDING);
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, ASCENDING);
}
}

private void SortGridView(string sortExpression, string direction)
{
DataTable dt = getData().Tables[0];
DataView dv = new DataView(dt);

dv.Sort = sortExpression + direction;
gvSortable.DataSource = dv;
gvSortable.DataBind();
}
}

.aspx file

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sorting Gridview</title>
</head>
<body>
<form id="form1" runat="server">

<asp:GridView ID="gvSortable" runat="server" Width="100"
AutoGenerateColumns="false"
AllowSorting="true" OnSorting="sortGv">
<Columns>
<asp:boundfield DataField="user_id" HeaderText="Id" SortExpression="user_id" />
<asp:boundfield DataField="name" HeaderText="Name" SortExpression="name" />
<asp:boundfield DataField="age" HeaderText="Age" SortExpression="age" />
</Columns>

</asp:GridView>

</form>
</body>
</html>

Add into the webconfig

<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=YOUR_SERVER_URL_HERE;Initial Catalog=YOUR_DB_NAME;Persist Security Info=True;User ID=YOUR_USER_NAME;Password=YOUR_PASSWORD;" providerName="System.Data.SqlClient"/>
</connectionStrings>

If you stick all of this code into your project and have a table (tbl_user) with user_id (int), name (varchar) and age (int) then your gridview will be up and working already!

You can choose to divert from the above and go with different options, but for seeing it working the code above is all that you need.

I’m going to revisit this post later to add in some options and comments however for now I have to go finish the project that I needed this sortable gridview for in the first place!

Project: Customizing the Windows Forms DataGrid

Learning how to change the display of tabular data on a windows form datagrid. (Apparently not as simple as bgcolor = … )

Requirements:
The form will need to adjust visually according to the status of the row. For example, changing to gray when the row is selected and a different colour to indicate focus.