Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataGrid onclick-javascript problem [modified]

DataGrid onclick-javascript problem [modified]

Scheduled Pinned Locked Moved ASP.NET
helpjavascripthtmltutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhruvil
    wrote on last edited by
    #1

    Hello All, I have a datagrid control on webpart, in which I am displaying two out of six columns from a dataset. When somebody click on one row, I want to display all six values for that row on the same webpart without postback. i made this datagrid clickable. i m passing value using the following code. public void dgSpeakerEvents_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.DataItem!=null) { e.Item.Attributes.Add("onmouseover","this.style.cursor='hand'"); e.Item.Attributes.Add("onclick","ShowDetails('"+ DataBinder.Eval(e.Item.DataItem, "TOPIC_NM").ToString()+ "','"+ DataBinder.Eval(e.Item.DataItem, "CITY").ToString()+ "','"+ DataBinder.Eval(e.Item.DataItem, "STATE").ToString()+ "');"); //e.Item.Attributes.Add("onmouseout", "HideTooltip();"); } } but when i clicked on datagrid, it shows an error: object expected. i checked in the html source code generated by the browser, values passing correctly. my javascript function is :

    **

    VenueDetail

    **

    function detail() { function ShowTooltip(name,city,state) { document.getElementById('td0').innerText=name; document.getElementById('td1').innerText=city; document.getElementById('td2').innerText=state; X=event.clientX+document.body.scrollLeft; Y= event.clientY + document.body.scrollTop + 10; Popup.style.display='block'; Popup.style.left = X; Popup.style.top = Y; } } function HideTooltip() { Popup.style.display='none'; } If any body can suggest me with good example.Thanks. Dhruvil -- modified at 16:45 Monday 19th June, 2006

    M 1 Reply Last reply
    0
    • D Dhruvil

      Hello All, I have a datagrid control on webpart, in which I am displaying two out of six columns from a dataset. When somebody click on one row, I want to display all six values for that row on the same webpart without postback. i made this datagrid clickable. i m passing value using the following code. public void dgSpeakerEvents_ItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.DataItem!=null) { e.Item.Attributes.Add("onmouseover","this.style.cursor='hand'"); e.Item.Attributes.Add("onclick","ShowDetails('"+ DataBinder.Eval(e.Item.DataItem, "TOPIC_NM").ToString()+ "','"+ DataBinder.Eval(e.Item.DataItem, "CITY").ToString()+ "','"+ DataBinder.Eval(e.Item.DataItem, "STATE").ToString()+ "');"); //e.Item.Attributes.Add("onmouseout", "HideTooltip();"); } } but when i clicked on datagrid, it shows an error: object expected. i checked in the html source code generated by the browser, values passing correctly. my javascript function is :

      **

      VenueDetail

      **

      function detail() { function ShowTooltip(name,city,state) { document.getElementById('td0').innerText=name; document.getElementById('td1').innerText=city; document.getElementById('td2').innerText=state; X=event.clientX+document.body.scrollLeft; Y= event.clientY + document.body.scrollTop + 10; Popup.style.display='block'; Popup.style.left = X; Popup.style.top = Y; } } function HideTooltip() { Popup.style.display='none'; } If any body can suggest me with good example.Thanks. Dhruvil -- modified at 16:45 Monday 19th June, 2006

      M Offline
      M Offline
      Mircea Grelus
      wrote on last edited by
      #2

      First you should display all the six columns in the datagrid and hide the columns that you don't want to be visible using e.Item.Attributes.Add("display", "none") in datagrid_ItemCreated event. This will ensure that the specific columns will be present in the aspx page, but not visible to the user. You need them to be present in order to be able to show them without a postback. Then, add a control to the webpage where you will display the hidden columns when the user clicks on an item. When the user clicks on an item call a javascript function that will read the values from the specific hidden columns and display them in the control. Your code above for clicking on an item in the datagrid is not correct. Adding an attribute to the datagrid will result in calling the javascript function when the user clicks on the datagrid, and not an specific item in it. You need to add an attribute to each item in the datagrid. See this article[^] as an example on how to create javascript events for items in a datagrid. regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups