How to implement OnItemDataBound to highlight a selected item

liunx

Guest
Hi, I am building a glossary page in which I have 3 repeaters. One is an alphabet bar on top horizontally. One is below which lists all the terms that start with a certain letter. And the 3rd repeater shows the definition. I want to highlight the selected term. I created the terms as linkbuttons. People told me to use OnItemDataBound, OnItemCreated. I tried so many things and nothing works. Can anyone provide an actual solution? In the current code, I used response.write to see which color is returned. And red is returned when i click on the term. But since it's not returne to the repeater, but to the SetForeColor function nothing happens. I don't know how to pass the color back to the repeater.
Thanks alot for the help.

Here is the relevant code:

private Color SetButtonBackColor(object dataItem)
{
Response.Write("
In SetButtonBackColor Function");

string _initial = dataItem.ToString();
// string _initial = (string)((DataRowView)dataItem)["TermIndex"];
Response.Write("
DataItem is " + dataItem);
Response.Write("
ViewState is " +(string) ViewState["TermIndex"]);
Response.Write("
Initial is: "+ _initial);

if ((string) _initial == (string) ViewState["TermIndex"])
{
Response.Write("
Red");
return Color.Red;
}
else
{
Response.Write("
Blue");
return Color.Blue;
}
private void BindTerm(object term)
{
//create a connection to the db
OleDbConnection oCxn = dbConnectDataDictionary();
ViewState["TermIndex"] = term;
SetButtonForeColor(term);
Response.Write("
term in BindTerm is: " + term);
Response.Write("
ViewState in BindTerm is: " + ViewState["TermIndex"]);

// SetButtonBackColor(Container.DataItem, "[TermIndex]");
// FillGlossary(ref oCxn, TermsQuery, ref GlossaryRepeater, term);

//Data set Two
DataSet _data3 = new DataSet();

string _Query = "SELECT[attribute name] AS TermIndex, [attribute type], [source for raw data], definition FROM [Attributes] WHERE [Attribute Name] like '{0}'";
string _cmdTerm = String.Format(_Query, term);

OleDbDataAdapter _adapter3 = new OleDbDataAdapter(_cmdTerm, oCxn);

_adapter3.Fill(_data3);

GlossaryRepeater.DataSource = _data3.Tables[0].DefaultView;
GlossaryRepeater.DataBind();

//close the connection
dbRelease (ref oCxn);
}
public void showTerm(Object sender, RepeaterCommandEventArgs e)
{
BindTerm(e.CommandName);
}
</script>

<asp:repeater runat="server" id="Glossary" OnItemCommand = "showTerm" >
<HeaderTemplate>
<div style="background-color:7B84BE;color:white;height:20px;"> <big><b><%# SetHeader() %></b></big></div>
<div style="background-color:#F3F3FB;height:400px;overflow:auto; padding: 10px; line-height:200%; font-size: x-small">
</HeaderTemplate>

<ItemTemplate>
<asp:LinkButton id="lb" runat="server"
ForeColor='<%# SetButtonForeColor(Container.DataItem)%>'
Text='<%# DataBinder.Eval(Container.DataItem,"[TermIndex]")%>'
CommandName ='<%# DataBinder.Eval(Container.DataItem,"[TermIndex]")%>' />
<br />
</ItemTemplate>

<FooterTemplate>
</div>
<div style="background-color:7B84BE; color:white;height:20px;"> <b><%# SetFooter() %></b></div>
</FooterTemplate>
</asp:repeater>Problem Solved. Had to rebind the Glossary again.
 
Back
Top