locked
Ajax RRS feed

  • Question

  • User491718545 posted

    Hi,

    How to  take selected cell header text and  table row id using ajax..

    i have one table when i drag table cell table cell color wil be orange..that particular selected cell header text and row id want to get??

    Exam

    id    Name          01  02

    1      sankar        p     a      when i select cell p,a want to get headertext and id--my result will be  1 01,1 02

    2       Naveen      p     p

    give me solution for that above question pl??

    Thanks..

    Tuesday, October 22, 2013 12:25 AM

Answers

  • User-417640953 posted

    Hi ShriNaveen,

    I'm glad to you post the issue to asp.net forum.

    From your description, I see that you want to select the text of table cells. Set the background of selected cells as "orange" and get the cell's header or position.

    If you want to change the html element text selection default color. Please use property unselectable and onselectstart.

    Below is a simple demo for it.

     <script src="../../Scripts/jquery-1.7.1.js"></script>
        <script>
            //set globe a flag 
            var flag = false;
            $(function () {
                $(document).mousedown(function (event) {
                    $("#MyTable").find("td").removeClass("selectedCell");
                    $("#MyTable").find("td").css("background-color", "white");
                });
                $(document).mouseup(function () {
                    flag = false;
                });
                $("#MyTable").find("td").mousedown(function () {
                    flag = true;
                }); 
                $("#MyTable").find("td").mouseup(function () {
                    flag = false;
                });
                $("#MyTable").find("td").mousemove(function () {
                    if (flag) {  
                        $(this).css("background-color", "orange");
                        $(this).addClass("selectedCell");
                    } 
                });
                
                //you can get the text, position of selected cells by the class "selectedCell"
                //your code.....
            })
             
        </script> 
    
    <body unselectable='on' onselectstart='return false;'>
        <form id="form1" runat="server" >
        <div>
        <table id="MyTable" border="1" >
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>01</th>
                <th>02</th>
            </tr>
            <tr >
                <td >1</td>
                <td>sankar</td>
                <td>p</td>
                <td>a</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Naveen</td>
                <td>p</td>
                <td>p</td>
            </tr>
        </table>
        </div> 
        </form>
    </body>

    In above code, you can get the selected cells by it class 'selectedCell'. Then you can get it's header or id easily.

    Thanks.

     

    Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 24, 2013 4:42 AM