如何手动将数据绑定到数据列表

发布于 2024-12-09 01:18:56 字数 826 浏览 1 评论 0原文

我希望用户能够单击一个按钮,然后它运行一个函数,然后在数据列表中显示结果。

我知道我可以获取数据并通过我的表绑定它

Sub BindCommsDataList(ByVal dlComms As DataList, ByVal sAddrno As String, ByVal sNameNo As String)
    Dim mySelectQuery As String = "SELECT * FROM table"
    Dim myConnection As New MySqlConnection(Session("localConn"))
    Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myDataAdapter = New MySqlDataAdapter(myCommand)
    Dim myDataSet As New DataSet
    myDataAdapter.Fill(myDataSet, "comms")
    dlComms.DataSource = myDataSet
    dlComms.DataKeyField = "seq"
    dlComms.DataBind()
    myConnection.Close()
End Sub

但是我如何运行手动绑定数据的函数

编辑:

恢复的数据将采用文本格式。所以理想情况下我只想做..

RtnDealerName.Text = xoGetWebPage.RtnDealerName

但它说我无权访问 RtnDealerName

I want to be able for a user to click on a button and then it runs a function and then shows the results in the data list.

i know i can get data and bind it through my tables

Sub BindCommsDataList(ByVal dlComms As DataList, ByVal sAddrno As String, ByVal sNameNo As String)
    Dim mySelectQuery As String = "SELECT * FROM table"
    Dim myConnection As New MySqlConnection(Session("localConn"))
    Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myDataAdapter = New MySqlDataAdapter(myCommand)
    Dim myDataSet As New DataSet
    myDataAdapter.Fill(myDataSet, "comms")
    dlComms.DataSource = myDataSet
    dlComms.DataKeyField = "seq"
    dlComms.DataBind()
    myConnection.Close()
End Sub

But how do i run a function which binds data manually

EDIT:

The data revived back will be in text format. So ideally i just want to do..

RtnDealerName.Text = xoGetWebPage.RtnDealerName

but it says i dont have access to RtnDealerName

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2024-12-16 01:18:56

我认为没有任何方法可以将项目直接添加到 DataList 控件,但您可以使用结果来构建数据源控件,例如 DataTable:

DataTable table = new DataTable();
table.Columns.Add("Col1", typeof(string));
table.Columns.Add("Col2", typeof(string));

TableRow row = table.NewRow();
row.SetField<string>("Col1", "Foo");
row.SetField<string>("Col2", "Bar");
table.Rows.Add(row);

DataList1.DataSource = table;
DataList1.DataBind();

以下是 DataList 控件的一些简单标记:

<asp:DataList ID="DataList1" runat="server">
    <ItemTemplate>
        <%#Eval("Col1")%>: <%#Eval("Col2")%>
    </ItemTemplate>
</asp:DataList>

I don't think there's any way to add items directly to the DataList control, but you can use the results to build a datasource control, like a DataTable for example:

DataTable table = new DataTable();
table.Columns.Add("Col1", typeof(string));
table.Columns.Add("Col2", typeof(string));

TableRow row = table.NewRow();
row.SetField<string>("Col1", "Foo");
row.SetField<string>("Col2", "Bar");
table.Rows.Add(row);

DataList1.DataSource = table;
DataList1.DataBind();

Here's some simple markup for the DataList control:

<asp:DataList ID="DataList1" runat="server">
    <ItemTemplate>
        <%#Eval("Col1")%>: <%#Eval("Col2")%>
    </ItemTemplate>
</asp:DataList>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文