-
May 14th, 2010, 10:21 AM
#1
Disable specific button from set of programatically created buttons?
Not knowing the exact number of labels needing to be created, I have created multiple instances of Linkbuttons "mLbtnPage" and have assigned each a different ID. On clicking a certain linklabel it successfully changes to gray. All the other linklabels are then supposed to turn blue. My method however only checks if the last created linklabel needs to be turned to blue instead of checking every label. I have been stuck on this for AGES and the only way I can think of tackling this problem is by sticking all the labels in a Gridview but Im hoping there is a simpler way!!
Code:
protected void CreateSetOfLinklabels()
{
for (int i = 1; i < miPages + 1; i++)
{
// Add label with corresponding page no
mLbtnPage = new LinkButton();
mLbtnPage.ID = i.ToString();
mLbtnPage.Text = i.ToString();
holderPages.Controls.Add(mLbtnPage);
mLbtnPage.Click += new EventHandler(lbtnPage_Click);
Literal literalSpace = new Literal();
literalSpace.Text = " ";
holderPages.Controls.Add(literalSpace);
// Current page
if (Convert.ToInt32(mLbtnPage.ID) == miSelectedPage)
{
mLbtnPage.ForeColor = System.Drawing.Color.Gray;
}
}
protected void lbtnPage_Click(object sender, EventArgs e)
{
if (sender is LinkButton)
{
LinkButton linkbutton = sender as LinkButton;
miSelectedPage = int.Parse(linkbutton.ID);
SetDefaultLinkButtonProperties();
// Set properties of selected linkbutton
linkbutton.ForeColor = System.Drawing.Color.Gray;
// Create a table with the loaded details
CreateTblReportSelection(miSelectedPage);
}
}
protected void SetDefaultLinkButtonProperties()
{
// Return all other linklabels to default color
mLbtnPage.ForeColor = mLbtnPage.ID != Convert.ToString(miSelectedPage) ? System.Drawing.Color.Blue : System.Drawing.Color.Gray;
}
#endregion
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|