用于上传部分网页的AJAX Extensions

时间:2014-07-31 17:15:53

标签: asp.net ajax

我正在尝试使用AJAX Extensions上传部分网页,触发列表框。

而不是“usernames”,它会在每次打勾后打印出大量的“System.Data.DataRowView”。

ASPX:

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="Timer2" Interval="10000" OnTick="Timer2_Tick" runat="server"></asp:Timer>
            <asp:ListBox ID="ListBox1" Width="500" Height="100" runat="server"></asp:ListBox><br />
        </ContentTemplate>
    </asp:UpdatePanel>

代码隐藏:

Try
    connStr = "connectionstring works"
    cmdStr = "SELECT [username] FROM [nregister] WHERE [onoffline]=@onoffline;"
    Using conn As New SqlConnection(connStr)
        Using cmd As New SqlCommand(cmdStr, conn)
            conn.Open()
            cmd.Parameters.AddWithValue("@onoffline", "on")
            Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
            Dim ds As DataSet = New DataSet()
            da.Fill(ds)
            ListBox1.DataSource = ds.Tables(0)
            ListBox1.DataBind()
        End Using
    End Using
Catch ex As Exception
    TextBox6.Text = "Who is Online: " & ex.ToString()
End Try

1 个答案:

答案 0 :(得分:0)

您需要指定要显示的数据源中的哪个字段:

<asp:ListBox DataTextField="username" ID="ListBox1" Width="500" Height="100" runat="server"></asp:ListBox>