有没有办法在不使用 SelectedIndexChanged 事件的情况下查找数据列表所选项目的所选索引 id(所选记录键值)?

发布于 2024-12-13 10:20:53 字数 437 浏览 2 评论 0原文

有什么方法可以找到数据列表所选项目的所选记录键值吗?

我正在做的是

  protected void dlstSelectedImages_SelectedIndexChanged(object sender, EventArgs e)
    {
        int indexId = Convert.ToInt32(dlstSelectedImages.DataKeys[dlstSelectedImages.SelectedIndex]);

    }

但我的数据列表 SelectedIndexChanged 没有触发(尝试使用:View State =“Enable”,AutoEventWireup =“true”,AutopostBack =“true”来触发事件),所以有没有其他方法来获取SelectedIndexChanged id或选定的记录键值

Is this any way to find selected record key value of selected item of datalist?

What is am doing is

  protected void dlstSelectedImages_SelectedIndexChanged(object sender, EventArgs e)
    {
        int indexId = Convert.ToInt32(dlstSelectedImages.DataKeys[dlstSelectedImages.SelectedIndex]);

    }

But my datalist SelectedIndexChanged is not firing (Itried with: View State="Enable", AutoEventWireup="true", AutopostBack="true" for firing the event ), so Is there anyother way to get the SelectedIndexChanged id or selected record key value

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

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

发布评论

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

评论(1

草莓酥 2024-12-20 10:20:53

您应该能够随时调用 dlstSelectedImages.SelectedIndex 来获取当前选定的索引。它不必驻留在 SelectedIndexChanged 事件处理程序中。 SelectedIndex 从零开始,其默认值为 -1。

只要所选索引发生更改(即每当为 SelectedIndex 分配新值),就会触发 SelectedIndexChanged 事件。通常,这将发生在 ItemCommand 或某些其他事件上:

  void Item_Command(Object sender, DataListCommandEventArgs e) 
  {
     // Set the SelectedIndex property to select an item in the DataList.
     dlstSelectedImages.SelectedIndex = e.Item.ItemIndex;

     // Rebind the data source to the DataList to refresh the control.
     dlstSelectedImages.Rebind();
  }

You should be able to call dlstSelectedImages.SelectedIndex at any time to get the currently selected index. It doesn't have to reside in an SelectedIndexChanged event handler. SelectedIndex is zero based and its default value is -1.

The SelectedIndexChanged event fires whenever the selected index changes (i.e. whenever SelectedIndex is assigned a new value). Typically, this would be on an ItemCommand or some other event:

  void Item_Command(Object sender, DataListCommandEventArgs e) 
  {
     // Set the SelectedIndex property to select an item in the DataList.
     dlstSelectedImages.SelectedIndex = e.Item.ItemIndex;

     // Rebind the data source to the DataList to refresh the control.
     dlstSelectedImages.Rebind();
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文