DataGrid onclick-javascript problem [modified]
-
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
-
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
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")
indatagrid_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.