getting error on row click

Discussion in 'ASP .Net' started by JohnE, Mar 20, 2010.

  1. JohnE

    JohnE Guest

    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
     
    JohnE, Mar 20, 2010
    #1
    1. Advertising

  2. JohnE

    JohnE Guest

    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" wrote:

    > 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
    >
    >
    >
    >
    >
     
    JohnE, Mar 21, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig
    Replies:
    2
    Views:
    2,881
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Nov 2, 2004
  2. Fernando Lopes
    Replies:
    0
    Views:
    3,196
    Fernando Lopes
    Apr 28, 2005
  3. Greg
    Replies:
    2
    Views:
    337
  4. D
    Replies:
    0
    Views:
    220
  5. john woo
    Replies:
    1
    Views:
    145
Loading...

Share This Page