- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我将如何着手在 asp 中运行查询并将其存储在数组中。然后用数组遍历每条记录,而不必每次都刷新页面。
例如
Sub loaddata()
Dim conn As New IfxConnection(connectionstring)
Dim results() As String
Dim i As Integer = 0
conn.ConnectionString = connectionstring
Try
conn.Open()
MsgBox("Made connection!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim cmd As New IfxCommand("Select name from table", conn)
Dim reader As IfxDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read()
results(i) = reader("name")
i += 1
End While
reader.Close()
conn.Close()
End Sub
结果存储在results(i)中
假设我有一个按钮,每次我都希望它转到结果数组中的下一个项目。我不希望页面刷新。我该怎么做?
最佳答案
您需要考虑如何设置您的页面。有很多方法可以做到这一点。
如果您获得页面加载上的所有记录,则可以将它们分配给各自的控件。如果它们在许多页面上,您可以使用 MultiView 控件来使其显示。
标记
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:Label ID="lblRecordOne" runat="server" />
</asp:View>
<asp:View ID="View2" runat="server">
<asp:Label ID="lblRecordTwo" runat="server" />
</asp:View>
</asp:MultiView>
<asp:Button ID="btNext" runat="server">Next</asp:Button>
代码隐藏
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Call your method that loads the data to results
Dim results() As String = loaddata()
'Set the data
lblRecordOne.Text = results(0)
lblRecordTwo.Text = results(1)
End Sub
Protected Sub btNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btNext.Click
'There is a much better way to go about this, but for this
'demos sake here is the basic idea
MultiView1.SetActiveView(View2)
End Sub
您要记住的是,每个 View 控件在 MultiView 中都有一个索引。因此,您需要一种方法来跟踪事件 View 是什么。当用户单击下一步按钮时,您将 View 前进一个。
在 MVC 应用程序方面
Controller
public class HomeController
{
// /Home/GetRecord/{id}
public ViewResult GetRecord(int? id)
{
int modelID;
if (id == null) { modelID = 0; }
ViewBag.CurrentID = modelID;
// This will send the value to the view
// I would refactor loaddata to only return one record at a time
// based on an id or an index
return View(loaddata(modelID));
}
}
查看
<label>@Model.Result</label>
@Html.ActionLink("GetRecord", "Home", new { id = ViewBag.CurrentID + 1 })
每次您单击 ActionLink 时,它都会通过一个人设置的记录。
如果第一条记录是Hello,第二条记录是World:
/Home/GetRecord/0 - 你好
/Home/GetRecord/1 - 世界
抱歉,我将其切换为 C#,我更喜欢徒手编写 C# 而不是 VB。 VB 中的代码非常相似。如果需要转换器就去http://converter.telerik.com/ .
关于asp.net - Asp 将查询放入数组并在不刷新页面的情况下通过它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11017041/
我试图在 Eclipse v3.7.2 中将 loopj .jar 库添加到我的项目中 首先,我将 .jar 添加到“lib”目录中,右键单击它并选择“添加到构建路径”。它编译得很好,但在执行时出现错
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Passing two-dimensional array via pointer int table[20
我在 Grafana 中的图表每隔几秒钟就会自动更新一次。随着数据的进入,右侧的最后一个数据点会暂时下降。最终会显示正确的值,但在几次更新时该值较低。这是正常的吗?可以修复吗? 最佳答案 也许,这会有
我不明白为什么我会收到臭名昭著的“IllegalStateException”以及以下代码: private void mergeQueryStrings(String url, Map parame
您好,我正在通过 .php 文件中的 JSON 回显将测试 Android 应用程序链接到 MySQL 数据库。 我能够用整个数据填充 ArrayList,但现在我想将数据分离到变量中,但我无法真正找
我想仅将对象的数据成员的值写入文件,因此这里我不能使用序列化,因为它会写入很多内容其他我不需要的信息。这是我通过两种方式实现的。一种使用字节缓冲区,另一种则不使用它。 不使用 ByteBuffer:第
可能是个简单的问题,但我似乎找不到答案。我正在动态创建一个页面,我可以在其中共享 Twitter 链接。 var twitter = document.createElement('a'); tw
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
尝试获取我在末尾为 $_SESSION 设置的值作为查询中的 user_id,而不是 $username。我似乎无法修改查询。我确信这对于这里的一些专家来说是非常简单的。 if(isset($_POS
有没有人可以帮助我,我有 mysql 查询,我已经在 phpmyadmin 中测试了它: select items.name, items.category, items.supplier_id, i
我正在尝试 push_back()一个„ std::vector 的符号. 我一直收到错误: character too large for enclosing character literal t
我有一个存储在 char * 中的压缩图像,我想将它放回 AVPacket,以便我可以将它放入 ffmpeg 解码器。有人可以展示如何做到这一点吗?任何示例或教程将不胜感激。 提前致谢 最佳答案 我向
password = str() while password != "changeme": password = input("Password: ") print("Thou Shall
所以我有一个 Map,其中有一些值被传递到一个方法中: public String doThis(Map context){ ..... } 我正在尝试向该 map 插入附加属性 String abc
我遇到了一些我无法弄清楚的问题...我正在编写一个带有接受拖放的 JList 的 Swing Java 应用程序。我想在将文件或文件夹从我的系统拖到 Java 应用程序上时更改光标。 最佳答案 我自己
我正在尝试确定一些关于如何编写异常消息的指南。 例如,让我们假设一个假设的函数必须接收恒定数量的字节(作为 bytes 对象),我们用 [1, 2, 3]。以下是所有可能的异常(exception)情
使用 JSONObject 发送到网络服务当我们将 double(整数)放入零时,该点将被删除 代码 double d = 123.00; JSONObject json = new JSONObje
在 WPF 中,如何将 DataGrid 放在 ComboBox 中以显示多列?像下面这样的东西似乎没有做任何事情:
我正在尝试使用自定义 QStandardItem 在两个 QListViews 之间进行拖放。 除了this document,我在网上找不到我需要的信息这有点帮助,但现在我被困住了。 从一个 QLi
如何将 PDF 放入 NSData 中?我在应用程序的文档目录中以字符串形式找到了 PDF 的位置。当我尝试通过电子邮件发送时,我在电子邮件正文中看到 PDF(而不是看到附件图标。我不知道这是否正常)
我是一名优秀的程序员,十分优秀!