c# - 根据选定的网格行项目检索隐藏对象属性 C#

标签 c# .net visual-studio datagrid telerik

我有一个 DataGrid,它的数据源是一个对象集合。现在数据网格设置为仅显示对象属性的一个子集。隐藏属性之一是 ID 变量,一旦选择了与该对象对应的行,我就需要获取该变量。

我知道您可以使用 SelectIndexChanged 事件处理程序来监听行点击....但是如何才能获得与行对应的实际原始对象呢?

最佳答案

I see you tagged your question with "Telerik".

Are you using a DataGrid or a RadGrid? Yes.

然后在您的 .aspx 文件中指定要调用的事件:

<telerik:RadGrid ID="RadGrid1" runat="server" 
            AutoGenerateColumns="False" 
            GridLines="None"  
            OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" > 
            (...)
</telerik:RadGrid>

并在您的 .asp 文件中声明该事件:

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    var dataItem = e.Item.DataItem; 
    if (dataItem != null) 
    { 
        int dataItemID = (dataItem As ObjectClassName).ID;
    } 
} 

*将“ObjectClassName”替换为您的对象类型。

关于c# - 根据选定的网格行项目检索隐藏对象属性 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9825802/

相关文章:

c# - 如何从组合框中获取选定的数据行

c# - 如何在运行批处理文件时隐藏 cmd 窗口?

c# - 无法加载文件或程序集 'Microsoft.Practices.Unity'

c# - 如何在 Azure Service Fabric 应用程序中注入(inject) IHttpClientFactory?

c# - 以 PNG 格式保存图像时出现 GDI+ 异常

.net - 编译 .net 应用程序时出现错误

c# - WPF 中的 DataGridView 列绑定(bind)

c - 如何在 Windows 中编译 Python 3.7 的 C 扩展

c - 为什么只有当可执行文件在 Visual Studio 下运行时 CreateFileA 才会失败?

c++ - Visual Studio 中的多项目解决方案 : spread the config of the main project