我有一個頁面上的一些鏈接,如:隱藏鏈接
< a id="Digg" runat="server">< img alt="Digg" id="imgDigg" runat="server" src="~/resources/images/icons/social/digg_32.png" border="0" />< /a>
我有一個數據庫表可在「轉」起來或關閉,在我的代碼後面我有以下幾點:
string[] SocialMedia = new string[] { "Twitter", "Facebook", "LinkedIn", "Digg", "Email", "Print" };
private void CheckForSocialMedia()
{
int i = 0;
for (i = 0; i < SocialMedia.Length; i++)
{
bool AddSocialMedia = (bool)AllowSocialMedia(SocialMedia[i]);
if (AddSocialMedia == false)
{
// Hide the link: Digg.Visible = false;
}
}
}
protected bool AllowSocialMedia(string sSocialMedia)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString);
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = " select Settings.AllowsocialMedia " +
" from ArticleSocialMediaSettings Settings " +
" inner join SocialMedia on Settings.SocialMediaId = SocialMedia.id " +
" where SocialMedia.NetworkName = '" + sSocialMedia + "'" +
" and Settings.RetailerId = '1234'";
myConnection.Open();
try
{
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
return (bool)myReader["AllowsocialMedia"];
}
}
catch (Exception ex)
{
throw ex;
}
return true;
}
如何在函數返回false時隱藏鏈接?還是有更好的方法來做到這一點?
這將取決於生成鏈接的代碼。請張貼。 – 2010-01-05 21:06:21
吉姆,鏈接被硬編碼.aspx頁上: <一個ID = 「Digg的」 RUNAT = 「服務器」>< /a> – Neil 2010-01-05 21:09:58