0

目前我有一个Ajax Timer每隔几秒执行一个函数。在我尝试从DataTable. 我不知道为什么。我试过调试。我什至在页面上放了标签来检查。

例如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>
4

1 回答 1

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
于 2012-07-07T10:16:23.597 回答