有没有办法在不使用 SelectedIndexChanged 事件的情况下查找数据列表所选项目的所选索引 id(所选记录键值)?
有什么方法可以找到数据列表所选项目的所选记录键值吗?
我正在做的是
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够随时调用 dlstSelectedImages.SelectedIndex 来获取当前选定的索引。它不必驻留在 SelectedIndexChanged 事件处理程序中。 SelectedIndex 从零开始,其默认值为 -1。
只要所选索引发生更改(即每当为 SelectedIndex 分配新值),就会触发 SelectedIndexChanged 事件。通常,这将发生在 ItemCommand 或某些其他事件上:
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: