HELP -- assign a dynamically created LinkButton to a string value

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 5304 Views - Last Post: 08 September 2009 - 07:30 AM Rate Topic: -----

#21 lm111  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Re: HELP -- assign a dynamically created LinkButton to a string value

Posted 04 September 2009 - 08:00 AM

View Postmasteryee, on 3 Sep, 2009 - 03:10 PM, said:

How well do you know javascript? You can create a javascript function that will respond to the <a> onclick event.

For example, let's say you create a javascript function like "function OpenPane(paneNumber). In there, you would need to gain access to your Accordion control then set the Accordion's selected index to the paneNumber value/index. You can create the link by doing something like <a href="java script:void(0)" onclick="OpenPane(0)">term</a>.

Here's a nice sample that gives you javascript access to the control and switches panes:
http://blog.benhall....rol-change.html

Now the difficult part is determining which term belongs to which pane number. In your btnSearch_Click method where you're loading the DataRows, iterate through all the rows and store all the terms + the row index into a global Dictionary<string, int> variable (from System.Collections.Generic). So if the first row contains the term "Happy", then add the value "Happy" and 0; if the second row contains the term "Happiest", add "Happiest" and 1 to the dictionary. In your DisplayPoem code, when you find a matching term, look it up in the dictionary variable and retrieve its corresponding integer value. Replace the term with <a href="java script:void(0)" onclick="OpenPane(corresponding integer value)">term</a>.

Does this make sense?

Ok--let's start with this. would this javascript function work?

 function Openpane(paneIndex) 
		{

			var behavior = $get("acc1").Accordionbehavior;

			behavior.set_SelectedIndex(paneIndex);
		}



and my btnSearch_Click function
 int rowIndex = 0;
			foreach (DataRow row in rows)
			{				
				Dictionary<string, int> dict = new Dictionary<string, int>();
				dict.Add(row["Term"].ToString(), rowIndex);
				rowIndex++;
			}


This post has been edited by lm111: 04 September 2009 - 08:37 AM

Was This Post Helpful? 0
  • +
  • -

#22 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: HELP -- assign a dynamically created LinkButton to a string value

Posted 04 September 2009 - 09:25 AM

That's almost the idea I was trying to get at. But you need to watch out with how you use your dictionary variable. You need to understand what your code is doing:

1) declaring a variable that is only local to the foreach loop, meaning once you exit the loop, the dict variable no longer exists
2) redeclaring the variable in each iteration, so you're effectively overwriting the previous reference

What I meant by declaring a "global" variable was you need to declare the dictionary at the class level of your form class so that all the methods in the form class can use it.

In response to your anchor question, you may be able to anchor to an accordion pane and have the web browser scroll to the correct definition if needed, but you still need to implement the javascript that will open the pane.
Was This Post Helpful? 0
  • +
  • -

#23 lm111  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 27-August 09

Re: HELP -- assign a dynamically created LinkButton to a string value

Posted 08 September 2009 - 07:30 AM

View Postmasteryee, on 4 Sep, 2009 - 08:25 AM, said:

That's almost the idea I was trying to get at. But you need to watch out with how you use your dictionary variable. You need to understand what your code is doing:

1) declaring a variable that is only local to the foreach loop, meaning once you exit the loop, the dict variable no longer exists
2) redeclaring the variable in each iteration, so you're effectively overwriting the previous reference

What I meant by declaring a "global" variable was you need to declare the dictionary at the class level of your form class so that all the methods in the form class can use it.

In response to your anchor question, you may be able to anchor to an accordion pane and have the web browser scroll to the correct definition if needed, but you still need to implement the javascript that will open the pane.

Hello,
Would it be possible to use JQuery? Here is a sample that I found
http://rndnext.blogs...ax-tooltip.html
I would not mind the pop up box.
Thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2