Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i write javascript code for aspx page that time it works but when i used this javascript code in content page that time it's not working properly..what should i do?

script code:
C#
<script type="text/javascript">
    var SelectedRow = null;
    var SelectedRowIndex = null;
    var UpperBound = null;
    var LowerBound = null;

    window.onload = function()
    {
        UpperBound = parseInt('<%= this.GrdATDataView.Rows.Count %>') - 1;
        LowerBound = 0;
        SelectedRowIndex = -1;
    }

    function SelectRow(CurrentRow, RowIndex)
    {
        if(SelectedRow == CurrentRow || RowIndex > UpperBound || RowIndex < LowerBound) return;

        if(SelectedRow != null)
        {
            SelectedRow.style.backgroundColor = SelectedRow.originalBackgroundColor;
            SelectedRow.style.color = SelectedRow.originalForeColor;
           //TextBox1.Text = GrdATDataView.SelectedRow.Cells[1].Text;
        //document.getElementById('TextBox1').value=GrdATDataView.rows[SelectedRowIndex].cells[1].innerText;
        //var sohil = document.getElementById(RowIndex).value;


        if(CurrentRow != null)
        {
            CurrentRow.originalBackgroundColor = CurrentRow.style.backgroundColor;
            CurrentRow.originalForeColor = CurrentRow.style.color;
            CurrentRow.style.backgroundColor = '#DCFC5C';
            //var grid = document.getElementById('<%=GrdATDataView.ClientID%>');
            //var cell = grid.rows[0].cells[5].innerText;
           // var Row = GrdATDataView.getAttribute("rel");


         document.getElementById('TextBox1').value=GrdATDataView.rows[RowIndex+1].cells[1].innerText;
            CurrentRow.style.color = 'Black';
            // TextBox1.Text = GrdATDataView.SelectedRow.Cells[1].Text;


        }

        }

        SelectedRow = CurrentRow;
        SelectedRowIndex = RowIndex;
        setTimeout("SelectedRow.focus();",0);

    }//TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;

    function SelectSibling(e)
    {
        var e = e ? e : window.event;
        var KeyCode = e.which ? e.which : e.keyCode;

        if(KeyCode == 40)
            SelectRow(SelectedRow.nextSibling, SelectedRowIndex + 1);
        else if(KeyCode == 38)
            SelectRow(SelectedRow.previousSibling, SelectedRowIndex - 1);

        return false;
    }
    </script>



code behind code:
C#
protected void GrdATDataView_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
    {
        e.Row.TabIndex = -1;
        e.Row.Attributes["onclick"] = string.Format("javascript:SelectRow(this, {0});", e.Row.RowIndex);
        e.Row.Attributes["onkeydown"] = "javascript:return SelectSibling(event);";
        e.Row.Attributes["onselectstart"] = "javascript:return false;";

    }
}
Posted
Updated 16-Oct-12 1:16am
v2
Comments
Mario Majčica 16-Oct-12 7:11am    
First you should show us what did you tried till now. We can't guess the code you wrote.
ZurdoDev 16-Oct-12 10:19am    
You need to see how the IDs of items get generated. They usually change when adding them as content so check what happens when you debug it.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900