Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 17th, 2009, 01:53 PM
Registered User
 
Join Date: Aug 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help with the accordion

The data for the accordion comes from a database, and each database record has an ID, a Term and a Definition field. The Term is the heading, and the Definition is in the content section.
Some definitions contain hyperlinks that reference other terms.
For example:
Term1: Here is the definition.
Term2: Here is the definition but it’s also referencing Term1
The accordion needs to update every time a user clicks on a hyperlink in the definition section. How can I accomplish this? I have the terms that need to be hyperlinks enclosed in <a href=”ID”>Term1</a> in the database.
Here is my code

.aspx

<asp:TextBox Tooltip="Search" runat="server"></asp:TextBox>
<asp:Button runat="server" Text="SEARCH" />
<cc1:Accordion runat="server" SuppressHeaderPostbacks="true" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="false">

<HeaderTemplate><%# ((DataRow)Container.DataItem)["Term"] %> </HeaderTemplate>
<ContentTemplate><%# ((DataRow)Container.DataItem)["Definition"] %></ContentTemplate>
</cc1:Accordion>


Code behind file
################################################## ###################################
protected void btnSearch_Click(object sender, EventArgs e)
{


DataTable dtblGlossary = (DataTable)Cache["GlossaryToFilter"];
if (dtblGlossary == null)
{
dtblGlossary = GetInfoFromDB();
Cache["GlossaryToFilter"] = dtblGlossary;
}



string filter = String.Format("Term LIKE '{0}*'", txtTerm.Text);
DataRow[] rows = dtblGlossary.Select(filter, "Term");

// Bind to Accordion
acc1.SelectedIndex = 0;
acc1.DataSource = rows;
acc1.DataBind();


}


public static DataTable GetInfoFromDB()
{
string connectionString = WebConfigurationManager.ConnectionStrings["TermDefinition"].ConnectionString;
SqlDataAdapter dad = new SqlDataAdapter("SELECT Term, Definition FROM DB", connectionString);
DataTable dtblGlossary = new DataTable();
dad.Fill(dtblGlossary);
return dtblGlossary;

}

################################################## ######################################

Thanks a lot!
  #2 (permalink)  
Old August 21st, 2009, 02:36 AM
Authorized User
 
Join Date: Jun 2009
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
Default More Information

Hi,
Actually I can't quite got you.Would you give more details?That would be a big more help.Thanks a lot!
  #3 (permalink)  
Old August 21st, 2009, 11:01 AM
Registered User
 
Join Date: Aug 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply. Which part do you need me to clarify?
  #4 (permalink)  
Old August 21st, 2009, 01:52 PM
Registered User
 
Join Date: Aug 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pull hyperlink from database into accordion

Does the following clarify things

I have two tables

TermDB
Term_Id--------------------Term
1---------------------------Term1
2 -------------------------- Term2
3--------------------------- Term3


DefinitionDB
Def_Id -------Definition ------------------------------------------------------------------------------------Term_Id
1 -----------Definition for Term 1 -----------------------------------------------------------------------------1
2 -----------Definition for Term 2 ------------------------------------------------------------------------------2
3 -----------Definition for Term 3 and also a reference to <a href=”1”>Term 1</a> ------------ 3


How can I make Term 1 above clickable (<a href=”1”>Term 1</a>) in my accordion so once clicked it links to the correct term based on the Term_Id?



Here is my SQL statement

SELECT TermDB.Term, DefinitionDB.Definition
FROM TermDB
INNER JOIN DefinitionDB
ON TermDB.Term_Id=DefinitionDB.Term_Id


Here is my code

.aspx

<asp:TextBox ID="txtTerm" Tooltip="Search" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="SEARCH" OnClick="btnSearch_Click" />
<cc1:Accordion ID="acc1" runat="server" SuppressHeaderPostbacks="true" FadeTransitions="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="false">

<HeaderTemplate><%# ((DataRow)Container.DataItem)["Term"] %> </HeaderTemplate>
<ContentTemplate><%# ((DataRow)Container.DataItem)["Definition"] %></ContentTemplate>
</cc1:Accordion>


Code behind file
################################################## ###################################
protected void btnSearch_Click(object sender, EventArgs e)
{


DataTable dtblGlossary = (DataTable)Cache["GlossaryToFilter"];
if (dtblGlossary == null)
{
dtblGlossary = GetInfoFromDB();
Cache["GlossaryToFilter"] = dtblGlossary;
}



string filter = String.Format("Term LIKE '{0}*'", txtTerm.Text);
DataRow[] rows = dtblGlossary.Select(filter, "Term");

// Bind to Accordion
acc1.SelectedIndex = 0;
acc1.DataSource = rows;
acc1.DataBind();


}


public static DataTable GetInfoFromDB()
{
string connectionString = WebConfigurationManager.ConnectionStrings["TermDefinition"].ConnectionString;
SqlDataAdapter dad = new SqlDataAdapter("AddTerms", connectionString);
DataTable dtblGlossary = new DataTable();
dad.Fill(dtblGlossary);
return dtblGlossary;

}

################################################## ######################################

Last edited by lm111; August 21st, 2009 at 02:01 PM..
  #5 (permalink)  
Old August 22nd, 2009, 03:12 AM
Authorized User
 
Join Date: Jun 2009
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
Default Try it

Hi,
I got you,and I have tried the code myself.You can add another field in your DefinitionDB table that reference antoher term_id.And in your code behind,you check if the newly-added field exists or not.
Term1
Definition for Term 1

Term2
Definition for Term 2

Term3
Definition for Term 3 and also a reference to Term 1.



I'll try my best to find another way to work it out!Hope helpful for you!
  #6 (permalink)  
Old August 27th, 2009, 07:55 AM
Registered User
 
Join Date: Aug 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you describe it more?

Thanks






Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.