我有一个带有通知图标的母版页,它返回sql查询计数中的数字。我无法在页面加载时更改文本,只是保持在“7”。如何在pageload上更改该文本?以下是我的代码
<li>
<table border="0" align="left" cellpadding="7" cellspacing="7"
style="margin-top:20px;" ><tr>
<td class="auto-style1">
<div id="noti_Container">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="../manage2.aspx"><i class="fa fa-envelope-o fa-fw"></i>
</asp:HyperLink>
<div class="noti_bubble"><asp:Label ID="Notifyme" runat="server" Text="7"/>
</asp:Label> </div>
</div>
</td>
<td class="auto-style1">
</li>
以下是Code Behind:
SqlConnection CON = new SqlConnection(Testdb);
{
CON.Open();
string ShiftTime = "SELECT count(discard) as alert FROM [Rejected].[dbo].[InQuestion] where discard = '0'";
SqlCommand ShiftTimecalculate = new SqlCommand(ShiftTime, CON);
SqlDataReader readershifttime =
ShiftTimecalculate.ExecuteReader();
readershifttime.Read();
if(readershifttime.hasrows)
{
Label noti_bubble = noti_Container.FindControl("Notifyme") as Label;
Notifyme.innertext = readershifttime["alert"].ToString();
readershifttime.Close();
}
答案 0 :(得分:1)
您的代码中的修改很少:
因此,您的代码将如下所示在母版页中:
<li>
<table border="0" align="left" cellpadding="7" cellspacing="7"
style="margin-top:20px;">
<tr>
<td class="auto-style1">
<div id="noti_Container" runat="server">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="../manage2.aspx">
<i class="fa fa-envelope-o fa-fw"></i>
</asp:HyperLink>
<div class="noti_bubble">
<asp:Label ID="Notifyme" runat="server" Text="7" />
</div>
</div>
</td>
<td class="auto-style1">
</li>
代码背后:
SqlConnection CON = new SqlConnection(Testdb);
{
CON.Open();
string ShiftTime = "SELECT count(discard) as alert FROM [Rejected].[dbo].[InQuestion] where discard = '0'";
SqlCommand ShiftTimecalculate = new SqlCommand(ShiftTime, CON);
SqlDataReader readershifttime =
ShiftTimecalculate.ExecuteReader();
readershifttime.Read();
if (readershifttime.hasrows)
{
Notifyme.Text = readershifttime["alert"].ToString();
readershifttime.Close();
}
}
我希望这会有所帮助。