HtmlAnchor[] anchorToConvert = new HtmlAnchor[]{
clickHere,
leavePage};
Button[] buttonToConvert = new Button[]{
login,
register};
i = 0;
for (i = 0; i < anchorToConvert.Length; i++)
{
DataRow[] result = ds.Tables[0].Select("htmlControl LIKE '" + anchorToConvert[i].ID.ToString() + "'");
if (result.Length > 0)
{
anchorToConvert[i].InnerHtml = result[0]["phrase"].ToString();
}
}
i = 0;
for (i = 0; i < buttonToConvert.Length; i++)
{
DataRow[] result = ds.Tables[0].Select("htmlControl LIKE '" + buttonToConvert[i].ID.ToString() + "'");
if (result.Length > 0)
{
buttonToConvert[i].Text = result[0]["phrase"].ToString();
}
}
I have two arrays of html elements i need to loop through, and use the elements id attribute to select content from a database. Rather than having to create two arrays and loop through them individually, is there someway i can make a more generic array that can contain both buttons and anchors?
You could use a list and check the type of the control in the list when you’re looping through: