listview的刷新问题

t69490741 2017-04-18 01:53:02
关于listview的,
我加载listview数据之后,选择listview的某一行,控件会刷新,选择的那一行会跳转到变成第一行
我希望选择某一行之后,位置保持不变

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="123.aspx.vb" Inherits="_123" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:ListBox ID="projectlist" drawSelectorOnTop="false" runat="server" Height="252px" Width="318px">
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="True">
<ContentTemplate>

<asp:TextBox ID="TextBox1" runat="server">

</asp:TextBox>
<input type="text" id="Text1" width="250px" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<input id="projectindex" type="text" name="projectindex" runat="server" />
</form>
</body>
</html>


Partial Class _123
Inherits System.Web.UI.Page
Private Sub SetProject(Optional strArrow As String = "")
Dim strPageArr As String() = projectlist.ToolTip.Split(",")
Dim intCount As Integer = 0
'
If strArrow = "-" Then strPageArr(0) = CInt(strPageArr(0)) - CInt(strPageArr(1))
If strArrow = "+" Then strPageArr(0) = CInt(strPageArr(0)) + CInt(strPageArr(1))
'
projectlist.Items.Clear()

Using DC As New SqlConnection(ConfigurationManager.AppSettings("SqlServer"))
DC.Open()
'
Using DA As New SqlDataAdapter("SELECT 编号,标题 FROM 项目", DC)
Using DS As New DataSet()
DA.Fill(DS, "Project")
intCount = DS.Tables("Project").Rows.Count
'
'DS.Tables("Project").Clear()
'DA.Fill(DS, CInt(strPageArr(0)), CInt(strPageArr(1)), "Project")

projectlist.DataSource = DS
projectlist.DataValueField = "编号"
projectlist.DataTextField = "标题"
projectlist.DataBind()
End Using
End Using
End Using
'
'projectlist.ToolTip = strPageArr(0) & "," & strPageArr(1)
End Sub

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim a As String
Context.Response.ContentType = "text/plain"
a = Context.Request.Params("projectindex").ToString()
'SetProject()

End Sub

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
projectlist.AutoPostBack = True
SetProject()
End If

End Sub

Protected Sub projectlist_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles projectlist.SelectedIndexChanged
Dim a As String
a = projectlist.SelectedItem.Text
TextBox1.Text = a
Text1.Value = a
End Sub

End Class

...全文
200 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
t69490741 2017-04-18
  • 打赏
  • 举报
回复
搞定,原来还是updatepanel得问题 改成如下方式即可,不需要一直更新

<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode ="Conditional">
        <ContentTemplate>
    <asp:ListBox ID="projectlist" runat="server" Height="252px" Width="318px">
    </asp:ListBox>
    </ContentTemplate>
    </asp:UpdatePanel>

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧