2012-07-06 45 views
0

目前我有一個Ajax Timer,它每隔幾秒執行一次函數。它工作得很好,直到我試圖從DataTable檢索數據。我不知道爲什麼。我試過調試。我甚至在頁面上放置了標籤來檢查。當我從DataTable中檢索值時,Ajax擴展(定時器)停止工作

例如,Ajax Timer

Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick 

    Label1.Text = DateTime.Now.ToLongTimeString() 

End Sub 

的數據列表(一個爲有問題的):

Protected Sub dlOrgProfile_ItemCreated(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlOrgProfile.ItemCreated 
    Dim bizLayerMgmt As BlOrganizations 
    Dim dt As DataTable 

    bizLayerMgmt = New BlOrganizations() 
    dt = bizLayerMgmt.getOrgDetails(userId).Tables(0) 

    ddl = CType(e.Item.FindControl("ddlCoType"), DropDownList) 
    Dim value As Integer = Convert.ToInt32(dt.Rows(0)(3)) 'I have narrowed the problem to this line, if I comment this line.. everything works perfectly 
    ddl.SelectedValue = value 
End Sub 

問題在於在dt.Rows(0)(3)。我不知道爲什麼。我需要用它從數據庫中檢索一些數據。

以防萬一它的前端..這裏是網站的標記。

<div class="content"> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"> 
      </asp:ScriptManager> 
      <asp:Timer ID="Timer1" runat="server" Interval="1000"> 
      </asp:Timer> 
      <asp:DataList ID="dlOrgProfile" runat="server" DataSourceID="odsOrgDetails" 
       EnableTheming="True" RepeatLayout="Flow" ShowFooter="False" ShowHeader="False"> 
       <ItemTemplate> 
        <h3> 
         <asp:TextBox ID="txBxCoName" runat="server" Text='<%# Eval("OrgName") %>'></asp:TextBox> 

         <div class="ddlSelect"> 
          <asp:DropDownList ID="ddlCoType" runat="server" DataSource='<%# listOrgType() %>' DataTextField="OrganizationType" DataValueField="OrgTypeID" > 
          </asp:DropDownList> 
         </div> 

         <h3> 
         </h3> 
         <a id="linkCoImg" href="upload_co_logo.aspx"> 
         <asp:Image ID="CoImg" runat="server" ImageUrl="~/logo/org/default.png" /> 
         <span>Change</span> </a> 
         <br /> 
         <div id="description"> 
          <textarea id="taCoDesc" rows="2" cols="1"><%# Eval("Description") %></textarea> 
         </div> 
         <br /> 
         <asp:Label ID="lblContacts" runat="server" Text="Contacts:"></asp:Label> 
         <br /> 
         <div id="contacts"> 
          <asp:TextBox ID="tbContactOffice" runat="server" CssClass="tbContacts"></asp:TextBox> 
          <asp:TextBox ID="tbContactFax" runat="server" CssClass="tbContacts"></asp:TextBox> 
          <asp:TextBox ID="tbContactMail" runat="server" CssClass="tbContacts2"></asp:TextBox> 
         </div> 
         <br /> 
         <asp:Button ID="btnSave" runat="server" CommandArgument='<%# Eval("OrgID") %>' 
          CommandName="save" Text="Save" /> 

        </h3> 

       </ItemTemplate> 
      </asp:DataList> 
      <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <Triggers> 
       <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> 
      </Triggers> 
      <ContentTemplate> 
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
      </ContentTemplate> 
      </asp:UpdatePanel> 
     </div> 
+0

當你說問題出在dt.Rows(0)(3)時,會發生什麼,它會在那裏凍結嗎?它是否會拋出可能被吞噬的錯誤?當您在調試模式下進行操作時,它會執行什麼操作? – swannee 2012-07-06 18:13:13

+0

當我使用dt.Rows(0)(3)運行代碼時,它將爲我的下拉列表設置選定的值,但Ajax計時器停止工作。這意味着我應該顯示當前日期和時間的Label1不起作用。如果我註釋掉dt.Rows(0)(3),我的Ajax Timer將工作,Label1將顯示當前的日期和時間。 – 2012-07-07 10:00:50

回答

0

好吧,我已經解決了我自己的問題..不過真的不明白爲什麼,但這個是我做的..而不是使用ItemCreated的,我用的ItemDataBound。

Protected Sub dlOrgProfile_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlOrgProfile.ItemDataBound 
    Dim bizLayerMgmt As BlOrganizations 
    Dim dt As DataTable 

    bizLayerMgmt = New BlOrganizations() 
    dt = bizLayerMgmt.getOrgDetails(userId).Tables(0) 

    ddl = CType(e.Item.FindControl("ddlCoType"), DropDownList) 
    Dim value As Integer = Convert.ToInt32(dt.Rows(0)(3)) 
    ddl.SelectedValue = value 
End Sub 
相關問題