【问题标题】:2 listviews working together2 个列表视图一起工作
【发布时间】:2015-05-15 08:52:27
【问题描述】:

我创建了一个带有两个列表视图的 asp.net 页面。一个带有名称和消息日期,一个带有消息当我单击第一个时,我想在另一个列表视图中突出显示该消息,但我真的不知道如何使它工作。我希望有人在这里给我一个提示。

我从第一个列表视图中得到了这样的方法。

Protected Sub lswBerichten2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lswBerichten2.SelectedIndexChanged

    Dim lblmsgid As Label = CType(lswBerichten2.Items(lswBerichten2.SelectedIndex).FindControl("msgid"), Label)
    HiddenMessageId.Value = lblmsgide.Text        

End Sub

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    我不完全确定您在寻找什么,我不确定意图是否完全清楚。 However I do believe you are binding data to two lists (I assume the same datasource, just different fields), and when an item in list 1 is selected, the corresponding item in list 2 will be selected.这是我的看法:

    首先列表框必须分配数据;通过以不同方式绑定显示和值,您可以允许包含数据 ID 字段。

    listBox1.DataSource = YourDatasource;
    listBox1.ValueMember = YourIDField;
    listBox1.DisplayMember = YourMessageOverview;
    
    listBox2.DataSource = YourDatasource;
    listBox2.ValueMember = YourIDField;
    listBox2.DisplayMember = YourMessageText;
    

    Then when the selection is changed, establish what the ID of the selected item is, then search the second list for an item with the same value.

    protected void listbox1_SelectedIndexChanged(object sender, EventArgs e)
    {
         string val = (listBox1.SelectedItem as DataRowView)["columnName"].ToString();
         listbox2.Items.FindByValue(val).Selected = true;
    }
    

    我没有检查过这段代码,但是我认为它应该不会有很多问题。

    另外,对于 C# 对 VB 问题的回复,我深表歉意,我已经多年没有在 VB 中工作了。

    根据这个stack answer更改了选定的项目值检索,希望有帮助吗?

    【讨论】:

    • 因此,如果您以 messageID 作为值进行绑定,那么所描述的方式听起来很有可能。
    • 你好 Nickson,谢谢我已经尝试过了,但是 aps.net 中没有 listbox1.SelectedItem.Value 这看起来像 Windows 表单的列表框。有没有办法在 asp.net 中做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多