Wednesday, May 02, 2007

Validating Grid View (Awesome Solution)

This function can be used to check for check box being checked in the itemtemplate of a grid view.
function selected()
{
var theGridView = document.getElementById("grdvLocationSpecific");

for ( var rowCount = 1; rowCount < theGridView.rows.length; rowCount++ )
{
if ( theGridView.rows(rowCount).cells(0).children(0)!=null)
{
if ( theGridView.rows(rowCount).cells(0).children(0).checked == true)
{
alert("Checked");

var bbolflag =false;
for(var child2count=0;child2count {
if ( theGridView.rows(rowCount).cells(1).children(0).children(child2count).selected == true)
{
bbolflag=true;
}
}
if(!bbolflag)
{
alert("Not Selected");
}

}
else
{
alert("UNchecked");
}
}
}
}

This function can be used to check for text box being checked in the itemtemplate of a grid view.

function selected123()
{
var theGridView = document.getElementById("grdvLocationSpecific");

for ( var rowCount = 1; rowCount < theGridView.rows.length; rowCount++ )
{
if ( theGridView.rows(rowCount).cells(0).children(0)!=null)
{
if ( theGridView.rows(rowCount).cells(0).children(0).checked == true)
{
alert("Checked");

if ( theGridView.rows(rowCount).cells(2).children(0).value != "")
{
alert("Entered");
}
else
{
alert("not entered");
}
}
else
{
alert("UNchecked");
}
}
}
}

Check out this post for more details:
http://forums.asp.net/2/1659719/ShowThread.aspx

No comments: