Tom Knowlton
asked on
Add new Attributes at runtime to Repeater control
After the datasource has been assigned to a repeater control, is it possible, in the C# code behind, to add attributes to certain LinkButtons (the repeater is a list of LinkButtons)?
LinkButton.Attributes.Add( "onClick", "return confirm('Are you sure you want to delete this item (and sub items if this is a folder)?');");
but only on certain ones, not on all of them
Thanks!
LinkButton.Attributes.Add(
but only on certain ones, not on all of them
Thanks!
ASKER
As long as I could still build it from a database that would be fine.
Not very familiar with a bulleted list or the advantages over a repeater.
Why wouldn't a repeater work?
Not very familiar with a bulleted list or the advantages over a repeater.
Why wouldn't a repeater work?
Apologies, The BullitedList will not give you the functionality you require. It does give you a neat way of creating a list of link buttons however it doens't expose them to allow you to apply an on click function.
I'll work up an example using the Repeater class.
I'll work up an example using the Repeater class.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
McExp:
Does your solution allow me to apply the Attribute to specific rows of the repeater?
Does your solution allow me to apply the Attribute to specific rows of the repeater?
Yes, what is your criteria?
All you need to do is add a conditional statment around the "lbTempTest.Attributes.Add " statment
All you need to do is add a conditional statment around the "lbTempTest.Attributes.Add
ASKER
I think my criteria will be based on LinkButton "Text"
If "LinkButton.Text == <some value>" then add attribute
That sort of thing.
I think what you have already provided me should be enough!!
I'll know for sure when I get in to work on Monday.
Tom
If "LinkButton.Text == <some value>" then add attribute
That sort of thing.
I think what you have already provided me should be enough!!
I'll know for sure when I get in to work on Monday.
Tom
ASKER
For my future reference:
protected void FirstUseStepsStatus_ItemDa taBound(ob ject sender, RepeaterItemEventArgs e)
{
LinkButton lbTempTest = e.Item.FindControl("LinkBu ttonStep") as LinkButton;
if (lbTempTest != null)
{
if (lbTempTest.CommandArgumen t == "2")
{
lbTempTest.Attributes.Add( "onClick", "return confirm('Do you want to add another Debt Item?');");
}
}
}
protected void FirstUseStepsStatus_ItemDa
{
LinkButton lbTempTest = e.Item.FindControl("LinkBu
if (lbTempTest != null)
{
if (lbTempTest.CommandArgumen
{
lbTempTest.Attributes.Add(
}
}
}
<asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="LinkButton">
</asp:BulletedList>