Repeater Control

G

Guest

I want to use a repeater to display a button for every item in the cache.
Each button should have the key of the cache object as its Text property and
it should remove that particular object from the cache.
So if I have two objects in the cache with keys key1, key2, respectively,
the buttons should be labeled and named so. On click of the button key1, the
following should occur:

Cache.Remove(key1);

I have written some code for this alrerady. However the cache is not cleared
when I click any of the buttons.

This is the code for the page load event:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Hashtable cacheTable = new Hashtable();
foreach(DictionaryEntry entry in Cache)
{
cacheTable.Add(entry.Key.ToString(), entry.Value);
}
repCacheButtonRepeater.DataSource = cacheTable;
repCacheButtonRepeater.DataBind();
}
}

The following is the code for the button click event:

private void Button_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
Cache.Remove(e.CommandName);
}

This is the HTML code for the template:

<ItemTemplate>
<tr>
<td><asp:Button CommandName="key" Text=<%#
DataBinder.Eval(Container.DataItem, "value")%> Runat=server/></td>
</tr>
</ItemTemplate>

Can anyone help me with a solution for my problem?

Hector
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top