Click here to Skip to main content
15,891,762 members
Articles / Desktop Programming / Windows Forms

DataGridView Custom Headers in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.56/5 (16 votes)
9 Mar 2009CPOL3 min read 185.6K   8.7K   47  
How to give Custom Headers to your DataGridView
// Copyright (c) 2008, The Code Project. All rights reserved.
var obid, obtid, value

function rateItem(objId, objTypeId, forceComment){
	if(objId > 0 && objTypeId > 0){
		obid  = objId.toString();
		obtid = objTypeId.toString();
		value = 0;
		
		
		var elems = document.getElementsByTagName("input");
		var reg = /.+VoteRBL_\d{1}/;
		
		for (var i = 0; i < elems.length; i++){
			var attr = elems[i].getAttribute("id");
			if(!attr)continue;
			if(reg.test(attr)){
				var radio = document.getElementById(attr);
				if(radio&&radio.checked){
					value = radio.getAttribute("value");
					break;
				}
			}
		}
		
		var comment=$("#RateComment")[0];
		comment = comment.value.replace(/^\s+|\s+$/g,'');
		
		if (value <= 0)
			ShowErrorMessage("You must select a value to vote");
		else if (value <=2 && comment == '' && forceComment)
			ShowErrorMessage("You must provide a comment");
		else {
			PrepElements();
			$.get("/Script/Ratings/Ajax/RateItem.aspx?obid=" + obid + "&obtid=" + obtid + "&rvv=" + value + "&rvc=" + escape(comment), callback);
		}
	}
	return false;
}

function callback(data){
	if(data.length > 0){
		var voteRes = $("#voteRes")[0];
		if(voteRes) {
			voteRes.innerHTML = data;
			voteRes.style.display = "";
		}
		voteRes = $("#CurRat")[0];
  		if(voteRes)voteRes.style.display = "none";
	}
	var loader = $("#loaderImg")[0];
	if(loader&&loader.style)loader.style.display = "none";
}

function PrepElements(){
	var loader = $("#loaderImg")[0];
	if(loader&&loader.style.display == "none")
		loader.style.display = "";
		
	loader = $("#voteTbl")[0];
	if(loader)loader.style.display = "none";

	loader = $("#voteRes")[0];
	if(loader)loader.style.display = "none";

	loader = $("#RateComDiv")[0];
	if(loader)loader.style.display = "none";
}

function ShowErrorMessage(msg){
	var loader = $("#loaderImg")[0];
	if(loader)loader.style.display = "none";
	
	alert(msg);
	/*
	var voteRes = $("#voteRes");
	if(voteRes) {
		voteRes.innerHTML = "An error occurred. Your vote has not been saved. Please try again later.";
		voteRes.style.display = "";
	}
	*/
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions