Jaicickebsive
New Member
On my website, I use the media player 7 active x object to play music, i put the songs in a table and all a user has to do is click on an image next to the printed song name and an onclick event is fired and the song name is able to be passed to client side script to be played by the media player. Using the datagrid control, how could i use an "onclick" event to pass the name of the song (which comes to from a database) to and onclick event. In classic asp I would just write the table out like this:<BR>For<BR>response.write "<td><img src=somepic.gif onclick=playme('songfromdatabase')></td><td>song name</td>"<BR>Next<BR>All the examples i have seen for asp.net, u can use a client side event, but it would not be unique to the data in the datagridsI just finished solving this very problem as well as adding mouseover/mouseout events to a datagrid.<BR>Here's a code snippet of what I accomplished.<BR>Please note the following:<BR>- searchResults is the id of a datagrid<BR>- this adds events to the entire row<BR><BR>Dim searchRowCount As Byte = searchResults.Items.Count<BR>Dim colCount As Byte = customerTable.Columns.Count<BR><BR>For i = 0 To searchRowCount - 1<BR> searchResults.Items(i).Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#006699'; this.style.cursor='hand';this.style.color='#ffffff '; return true;")<BR> searchResults.Items(i).Attributes.Add("onmouseout", "javascript:this.style.backgroundColor=''; this.style.cursor='default';this.style.color=''; return true;")<BR> searchResults.Items(i).CssClass = "ctrlLabel"<BR> searchResults.Items(i).Attributes.Add("onclick", "javascript:window.location.href='CustomerAdmin.asp x?id=" & customerTable.Rows(i)("PersonID") & "';")<BR>Next<BR><BR><BR>- if you want to add the events to the table cell then you need to add an inner loop to the for/next that will look like this<BR><BR>For j = 5 To colCount - 1<BR> searchResults.Items(i).Cells(j).Attributes.Add("onclick", "javascript:alert('hello')")<BR>Next<BR><BR>hth<BR><BR>mattThanx Matt, I will go and try this out, but don't be surprised if I have some questions for you, .<BR><BR>MikeMatt, I am adding an Odblclick event to individual cells on my datagrid. I need to be able to pass the text value of each cell to client side script so an active x object can use it. I figured out that i can get the test by doing this: searchResult.Items(n).Cells(n).Text. Everytime i double click on the cells, the text is empty. But if I wanted to print out say "apple" it can just put 'apple' and that will print. I have tried everything to get the cell text to print out, by using Trim, putting '' around it, please help.<BR><BR>Server side code:<BR>'Note I am just putting an ondblclick event on the whole row for now using the first row and first column for each for testing<BR>Sub SetGridProperties()<BR>Dim i, music <BR><BR> For i = 0 to Pubs.Items.Count-1<BR> 'Tried this<BR>'music = replace(Pubs.Items(1).Cells(1).Text, " ", "|")<BR> 'Tried this<BR> 'music = Pubs.Items(1).Cells(1).Text<BR> Pubs.Items(i).Attributes.Add("OnDBLClick","PlayMe(Trim(Pubs.Items(0).Cells(0).Text))")<BR> Next<BR>End Sub<BR><BR>Client side Script<BR> Sub PlayMe(music)<BR> msgbox music<BR> End Sub