6

我使用 DevexpressGridView 显示所有TOPIC (id,title,content)

<dx:ASPxGridView ID="gv" runat="server"
OnSelectionChanged="gv_SelectionChanged" >

我有 grid_SelectionChanged 事件:

protected void gv_SelectionChanged(object sender, EventArgs e)
    {

        int id= selected row...???; //how can I get the value of selected row
        string sql = "select * from TOPIC where idTOPIC="+id;
        DataTable topic = l.EXECUTEQUERYSQL(sql);
        TextBox1.Text = topic.Rows[0][1].ToString();
    }

...

DevGridview 中似乎gv.SelectedRow不存在方法。

按照建议,我尝试过使用FocusedRowIndex方法,但我真的不知道获取所选行值的正确语法。

帮助!!!

4

4 回答 4

8

更改选择不同于更改焦点行。Selection有关两者之间的区别,请参阅文档。

您可以使用gv.GetSelectedFieldValues来获取被选中的行。

var ids = gv.GetSelectedFieldValues("id");
foreach( var id in ids )
    DoSomethingWithObject(id);

FocusedRowChanged如果您对焦点行感兴趣,您应该处理该事件。

您可以使用该FocusedRowIndex值来索引 的行gv.DataSource,例如:

DataTable ds = (DataTable)gv.DataSource;
var id = ds.Rows[gv.FocusedRowIndex]["id"];

或者你可以使用var id = gv.GetRowValues(gv.FocusedRowIndex, "id").

于 2013-10-06T08:45:13.543 回答
1

您还可以将选定的数据行作为

int rowHandle = gridView1.FocusedRowHandle;
   if (rowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
   {
    return this.gridView1.GetDataRow(rowHandle);
   }

这将返回 DataRow

请注意,这是我在 WinForms 中使用 Devexpress gridControl 时

于 2014-10-02T11:34:47.370 回答
1

经过长时间搜索谷歌后,我在这里找到了答案:http: //www.devexpress.com/Support/Center/Question/Details/Q347704

使用ASPxGridView.GetSelectedFieldValues方法在服务器端获取选定的行值。

于 2013-10-06T09:15:14.090 回答
1

If you want to get only ID field value you can use this

int id =  Convert.ToInt32(gv.GetRowValues(gv.FocusedRowIndex, "ID").ToString());

if you have an object you can use this

Personels selectedPersonel = gv.GetRow(gv.FocusedRowIndex) as Personels;

and get value method is

int ID = selectedPersonel.ID;
于 2017-07-27T06:28:42.647 回答