Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 2个列表视图一起工作_Asp.net_Vb.net - Fatal编程技术网

Asp.net 2个列表视图一起工作

Asp.net 2个列表视图一起工作,asp.net,vb.net,Asp.net,Vb.net,我创建了一个包含两个列表视图的asp.net页面。一个有名字和消息日期,另一个有消息,当我单击第一个时,我想在另一个列表视图中突出显示消息,但我真的不知道如何让它工作。我希望有人能给我一个提示 我从第一个列表视图中得到了这样的方法 Protected Sub lswBerichten2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lswBerichten2.SelectedIndexChanged Dim

我创建了一个包含两个列表视图的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

我不完全确定你在找什么,我不确定你的意图是否完全清楚。然而,我相信您正在将数据绑定到两个列表(我假设相同的数据源,只是不同的字段),当选择列表1中的一个项目时,列表2中的相应项目将被选择。以下是我的看法:

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

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

listBox2.DataSource = YourDatasource;
listBox2.ValueMember = YourIDField;
listBox2.DisplayMember = YourMessageText;
然后,在更改选择时,确定所选项目的ID,然后在第二个列表中搜索具有相同值的项目

protected void listbox1_SelectedIndexChanged(object sender, EventArgs e)
{
     string val = (listBox1.SelectedItem as DataRowView)["columnName"].ToString();
     listbox2.Items.FindByValue(val).Selected = true;
}
我没有检查这段代码,但是我认为它不应该有很多问题

我也为我对一个VB问题的C#回答道歉,我已经多年没有在VB工作了


根据此更改了所选项目值检索,希望能有所帮助?

因此,如果您使用messageID作为值进行绑定,那么所述方式听起来很可能是可行的。你好,Nickson,谢谢,我尝试过此操作,但在aps.net中没有listbox1.SelectedItem.value。这看起来像Windows窗体的listbox。在asp.net中有这样做的方法吗?