如何在devexpress gridcontrol中获取选定的行索引 [英] How to get selected row index in devexpress gridcontrol
问题描述
你好
我有一个Windoes表单应用程序和一个 Devexpress GridControl,我需要获取所选的行索引,例如从我的数据库中删除它,如何我做到了吗? GridControl的数据已从SQL数据库中获取。
预先感谢
我尝试过:
我试过在https://documentation.devexpress.com上阅读devexpress文件
for many houres我没找到答案。
Hello
I have a Windoes Form Application and a Devexpress GridControl inside it, I need to get the selected row index and for example delete it from my database, How shoud I do it ? GridControl's data has been fetched from SQL database.
Thanks in Advance
What I have tried:
I have tried reading devexpress documents in https://documentation.devexpress.com
for many houres bu I did Not find my answer.
推荐答案
我的devexpress上有点生疏,但在你的网格控件中,我认为你应该指定一个网格视图。从该网格视图中,为了从Id列中获取Id,您可以这样做。
I'm a bit rusty on my devexpress but in your gridcontrol i think you should be specifying a grid view. From that grid view, in order to get the Id from an Id column you would do.
devExpressGridView.GetFocusedRowCellValue("Id")
这将假设您的网格列包含标签为Id的列。因此,如果您的列标记为Index,那么您将使用Index切换Id。
This would assume that your grid's columns contain a column with label of Id. So if your column is labeled Index, then you would switch out Id with Index.
protected void btnEditItem_Click(object sender,EventArgs e)
{
试试
{
LinkButton btn =(LinkButton)发件人;
var gvr =(DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer)btn.NamingContainer;
var trt = gvr.ItemIndex;
}
catch(Exception ex)
{
}
}
protected void btnEditItem_Click(object sender, EventArgs e)
{
try
{
LinkButton btn = (LinkButton)sender;
var gvr = (DevExpress.Web.ASPxGridView.GridViewDataItemTemplateContainer)btn.NamingContainer;
var trt = gvr.ItemIndex;
}
catch (Exception ex)
{
}
}
这篇关于如何在devexpress gridcontrol中获取选定的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!