简体   繁体   English

根据另一个列表视图中的选择更改列表视图中的选定项目

[英]Change a selected item in a listview based on the selection in another listview

I have two list views.我有两个列表视图。 In the Item command event of the first Listview i am showing the second list view in modal popup using ajaxtoolkit.在第一个 Listview 的 Item 命令事件中,我使用 ajaxtoolkit 在模式弹出窗口中显示第二个列表视图。

protected void lvSelection_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    this.lvPopup.Visible = true;
    this.lvPopup.DataSource = linqdataSource;
    this.lvPopup.DataBind();

    this.mdlPopup.Show();
}

Now in the itemcommand event of the second list view I need to change the content of the selected item in the first listview.现在在第二个列表视图的 itemcommand 事件中,我需要更改第一个列表视图中所选项目的内容。

Is it possible to do that?有可能这样做吗?

protected void lvPopup_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    // Set the text of the first list view item to the selected item 
    // of the second list view.
    lstView1.Items[lstView1.SelectedIndex].Text = 
        lstView2.Items[lstView2.SelectedIndex].Text
}

I'd think that if you were to set the CommandName of the selector button in the first ListView to "Select" - from the second list view's ItemCommand event, you should be able to alter either the SelectedItemTemplate or the current item for the selected item in the first list.我认为,如果您要将第一个 ListView 中选择器按钮的 CommandName 设置为“Select” - 从第二个列表视图的 ItemCommand 事件,您应该能够更改 SelectedItemTemplate 或所选项目的当前项目在第一个列表中。

protected void lvPopup_ItemCommand(object sender, ListViewCommandEventArgs e)
{

   lvSelection.SelectedItemTemplate = "<div>woohoo!</div>";
   // OR...
   lvSelection.Items[lvSelection.SelectedIndex].SkinID = "SomeNewSkinForExample";


   mdlPopup.Hide();

}

Have you already tried to dynamically generate the items of the List?您是否已经尝试过动态生成 List 的项目?

On the event code of the 1st list, clear the Items from the 2nd list and populate it with whatever logic suits you.在第一个列表的事件代码上,清除第二个列表中的项目并使用适合您的任何逻辑填充它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM