getting error on row click


J

JohnE

Hello. I have a gridview that needs to have a nested gridview. I got it to
work using arrows but need to reclaim some real estate so I am moving over to
a row click to show the nested gridview. Will show the code at the end of
this post. What is occurring is the mouseover/onmouseout work. It is the
click of the row that causes the issue. I get a javascript error saying
'object required'. At the start of each row there is an 'Edit' that now also
throws the error but does go into the edit mode when the 'No' is clicked on
the error.

The error comes to this line in the javascript;

if (div.style.display == "none")

Here is the whole javascript plus the ondatabound code behind.

<script language="javascript" type = "text/javascript">
var currentlyOpenedDiv = "";
function CollapseExpand(object)
{
var div = document.getElementById(object);
if (currentlyOpenedDiv != "" && currentlyOpenedDiv != div)
{
currentlyOpenedDiv.style.display = "none";
}
if (div.style.display == "none")
{
div.style.display = "inline";
currentlyOpenedDiv = div;
}
else
{
div.style.display = "none";
}
}
</script>

protected void gvwChangeRequestList_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover",
"this.style.backgoundcolor='#4A4A4A'; this.style.cursor='pointer';
this.style.color='blue'");
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundcolor='#FFFFFF'; this.style.color='black'");
e.Row.ToolTip = "Click on the row to view any children to " +
e.Row.Cells[2].Text;

GridView child = (GridView)e.Row.FindControl("gvwChild");
if (child != null)
{
SqlDataSource dbChild = new SqlDataSource();
dbChild.ConnectionString =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
dbChild.SelectCommand = "SELECT * " +
"FROM tblChangeRequest " +
"WHERE IsChildOf = '" +
((DataRowView)e.Row.DataItem)["ChangeRequestID"].ToString() + "' " +
"ORDER BY DevTargetEndDate";
child.DataSource = dbChild;
child.DataBind();
}
e.Row.Attributes.Add("onclick", "javascript:CollapseExpand('" +
e.Row.Cells[3].Text + "')");
}
}


I found the basic row click info when googling. Can anyone see what is
wrong here as to why the error and how to keep the 'Edit' from being involved
in the row click?

Thanks for your time.

.... John
 
Ad

Advertisements

J

JohnE

Hi. For what I have below, there is more to add. After a break, I came back
and dug into this more. The nested gridview is there and populated. As I
had it display when the gridview opens. I found the problem in asking for
'object' is coming from the following line;

e.Row.Attributes.Add("onclick", "javascript:CollapseExpand('" +
e.Row.Cells[0].Text + "')");

When this line is commented out no error. When ('" + e.Row.Cells[0].Text +
"') this part is removed, no error. This is the object part of the
javascript function. So this is what should be looked at. And also a way to
avoid the first column with 'Edit' in it for editing the row.

Thanks...John



JohnE said:
Hello. I have a gridview that needs to have a nested gridview. I got it to
work using arrows but need to reclaim some real estate so I am moving over to
a row click to show the nested gridview. Will show the code at the end of
this post. What is occurring is the mouseover/onmouseout work. It is the
click of the row that causes the issue. I get a javascript error saying
'object required'. At the start of each row there is an 'Edit' that now also
throws the error but does go into the edit mode when the 'No' is clicked on
the error.

The error comes to this line in the javascript;

if (div.style.display == "none")

Here is the whole javascript plus the ondatabound code behind.

<script language="javascript" type = "text/javascript">
var currentlyOpenedDiv = "";
function CollapseExpand(object)
{
var div = document.getElementById(object);
if (currentlyOpenedDiv != "" && currentlyOpenedDiv != div)
{
currentlyOpenedDiv.style.display = "none";
}
if (div.style.display == "none")
{
div.style.display = "inline";
currentlyOpenedDiv = div;
}
else
{
div.style.display = "none";
}
}
</script>

protected void gvwChangeRequestList_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover",
"this.style.backgoundcolor='#4A4A4A'; this.style.cursor='pointer';
this.style.color='blue'");
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundcolor='#FFFFFF'; this.style.color='black'");
e.Row.ToolTip = "Click on the row to view any children to " +
e.Row.Cells[2].Text;

GridView child = (GridView)e.Row.FindControl("gvwChild");
if (child != null)
{
SqlDataSource dbChild = new SqlDataSource();
dbChild.ConnectionString =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
dbChild.SelectCommand = "SELECT * " +
"FROM tblChangeRequest " +
"WHERE IsChildOf = '" +
((DataRowView)e.Row.DataItem)["ChangeRequestID"].ToString() + "' " +
"ORDER BY DevTargetEndDate";
child.DataSource = dbChild;
child.DataBind();
}
e.Row.Attributes.Add("onclick", "javascript:CollapseExpand('" +
e.Row.Cells[3].Text + "')");
}
}


I found the basic row click info when googling. Can anyone see what is
wrong here as to why the error and how to keep the 'Edit' from being involved
in the row click?

Thanks for your time.

... John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top