Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm having table like this
 Response.Write("<table>")
        While intstartrecord <= intrecordcount
Response.Write("<tr>")
Response.Write("<td id="columno" onclick='showvalue()' value=" & intstartrecord & ">" & intstartrecord & "</td>")
           intstartrecord = intstartrecord + 1
           Response.Write("</tr>")

         End While
 Response.Write("</table>")

function showvalue()
{
alert(document.GetElementById("columnno").value)
}


In this When i click on any column i need to get that value. when i use this code i'm getting the same value whenever i clicked on any column ie., it is not recognizing the clicked column.

i tried getval(this) and googled but i'm not getting what i want

Please help me to do this
Posted
Comments
shah dipen 27-Jun-12 6:24am    
Hey have you got solution? if you have any difficulty reply immediately.
Agustee 27-Jun-12 8:19am    
i got the solution thanq.

I implemented the small thing in C# but i guess you shuold be able to change it to VB easily. This is working as you expected it to be. Tell me if you specifically need to make it work using IDs i can do that too.

here is the code behind for that

C#
protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<table>");

        int intstartrecord = 0;
        int intrecordcount = 10;

        while (intstartrecord <= intrecordcount)
        {
            Response.Write("<tr>");
            Response.Write(@"<td id='columno' onclick='showvalue(this)' value=" + intstartrecord + ">" + intstartrecord + "</td>");
            intstartrecord++;
           Response.Write("</tr>");


        }
        Response.Write("</table>");
    }


and here is the javascript function i put in the aspx file

XML
<script type="text/javascript">
    function showvalue(sender)
    {
        alert(sender.value);
    }
</script>


On a closing note: use string builder to tailor the complete string and then do response.write only once that would be better.
 
Share this answer
 
Comments
AshishChaudha 27-Jun-12 6:43am    
my 5!
Rahul Rajat Singh 27-Jun-12 6:44am    
thanks.
Agustee 27-Jun-12 8:03am    
thanq so much
Rahul Rajat Singh 27-Jun-12 8:06am    
you are welcome. if it worked then please mark the answer as solution as this would let other know that the problems is solved and the others with similar problem can also refer and benefit from it.
Agustee 27-Jun-12 8:18am    
Great answer your code works i got it
please check the id of your td..it is same for all the columns..thats why it is returning the same value for every column.


Thanks
Ashish
 
Share this answer
 
Comments
Agustee 27-Jun-12 8:21am    
yeah you are rite it is same for all columsn tats y i did not get it now i got it without id
Use array of id to separate the td id:

Response.Write("<td id="columno[intstartrecord]" onclick='showvalue()' value=" & intstartrecord & ">" & intstartrecord & "</td>")


Thanks,
Elangovan
 
Share this answer
 
Comments
Agustee 27-Jun-12 8:22am    
thanks for your reply
Give unique id to each td by using counter vaiable.
 
Share this answer
 
Comments
Agustee 27-Jun-12 8:36am    
thanks for the reply
You can create one counter, let say i, and increment it on each iteration of loop and modify your JS function like this way.
for(int i=0;i<n;i++)>
{
  Response.Write("<td  önclick='showvalue(column" & i & " )' id='column" & i & '>" & myval & "</td>");
}

function showvalue(id){
  alert(document.getElementById(id).innerText);
}
 
Share this answer
 
v2
Comments
Agustee 27-Jun-12 8:36am    
thanq

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