Javascript code for deleting the rows of datagrid

//Javascript code for deleting the rows of datagrid



function deletetrow(gridname)
{

var rowcount = document.all(gridname).rows.length;

if(rowcount>2)
{

while(rowcount!=1)
{

if(document.getElementById(gridname).rows(rowcount)!=null)
document.getElementById(gridname).deleteRow(rowcount);
rowcount--;
}

}

}


Comments

Author: Tirumala16 Sep 2011 Member Level: Bronze   Points : 1

Hi
function deletetrow(gridname){ var rowcount = document.all(gridname).rows.length; if(rowcount>2) { while(rowcount!=1) { if(document.getElementById(gridname).rows(rowcount)!=null) document.getElementById(gridname).deleteRow(rowcount); rowcount--; } }}
function im using for deleting the rows from the datagrid.
it returns the Javascript erro like
"System" is undefined.

please help me in this.

my C# code is like below

protected void itemDataBound(object sender,DataGridItemEventArgs e)
{
DataTable dtValues;
DropDownList list;
DropDownList list1;
int rowIndex = 0;

HtmlImage imgSearch;

dtValues = csDataAccess.DeviceStackGetMaster(sDeviceID);
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{

if(e.Item.FindControl("SelModel") != null)
{
list =e.Item.FindControl("SelModel") as DropDownList;

list.DataSource = GetModelDetailsForDDL(sDeviceID);

//list.SelectedValue = dtValues.Rows[0]["Model"].ToString();
list.DataTextField="Model";
list.DataValueField="ID";
list.DataBind();

}
if(e.Item.FindControl("SelFloor") != null)
{
list1 =e.Item.FindControl("SelFloor")as DropDownList;

list1.DataSource = GetFloorDetailsForDDL();
//list1.SelectedValue = dtValues.Rows[0]["Fllor"].ToString();
list1.DataTextField = "Floor";
list1.DataValueField = "ID";
list1.DataBind();
}
if (e.Item.FindControl("DeleteDevice") != null)
{
rowIndex=e.Item.ItemIndex;
////popup do display moredetails,.
imgSearch = (HtmlImage)e.Item.FindControl("DeleteDevice");
imgSearch.Attributes.Add("Onclick", "Javascript:ShowDeviceDetails(" + dgChildDeviceList + ")");
}

/*
if(e.Item.FindControl("txtCabinet") != null)
{
TextBox txtCabin;
txtCabin=(TextBox)e.Item.FindControl("txtCabinet");
txtCabin.Text = dtValues.Rows[0]["cabinet"].ToString();

}
if(e.Item.FindControl("txtRack") != null)
{
TextBox txtRack;
txtRack=(TextBox)e.Item.FindControl("txtRack");
txtRack.Text = dtValues.Rows[0]["Rack"].ToString();
}

*/

}


}



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: