locked
Get Selected Row's Column Value RRS feed

  • Question

  • User-1352355861 posted

    Hi All,

    I want to get value from spesific column that I selected row for.

    In the first line, it throws the following error:

    object reference not set to an instance of an object.

    protected void wdgTopSQL_RowSelectionChanged(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)
    {
        DataRowView drv = (DataRowView)wdgTopSQL.Behaviors.Selection.SelectedRows[0].DataItem;
        sqlid = drv[1].ToString();
    }

    I Inserted breakpoint and selectedrow count is 1.

    However, DataItem throws an error. How can I fix this?

    Friday, January 20, 2017 3:38 PM

All replies

  • User197322208 posted

    (DataRowView)wdgTopSQL.Behaviors.Selection.SelectedRows[0].DataItem;

    That means that wdgTopSQL.Behaviors.Selection.SelectedRows[0].DataItem is not a DataRowView.

    Friday, January 20, 2017 3:54 PM
  • User-1352355861 posted

    kamuran

    (DataRowView)wdgTopSQL.Behaviors.Selection.SelectedRows[0].DataItem;

    That means that wdgTopSQL.Behaviors.Selection.SelectedRows[0].DataItem is not a DataRowView.

    Even if i did it step by step, still throws an error in DataItem. How come it would be datarowview because it is obviously datarowview.

    GridRecord selectedRow = e.CurrentSelectedRows[0];
    DataRowView dataItem = (DataRowView)selectedRow.DataItem;
    DataRow dataRow = dataItem.Row;
    object[] valueArray = dataRow.ItemArray;
    int columnIndex = wdgTopSQL.Columns["SQL_ID"].Index;
    string sqlid = selectedRow.Items[columnIndex].Value.ToString();

    Friday, January 20, 2017 3:57 PM
  • User197322208 posted

    set a breakpoint here

    DataRowView dataItem = (DataRowView)selectedRow.DataItem;

    and see the type of selectedRow.DataItem

    Saturday, January 21, 2017 11:08 AM
  • User-707554951 posted

    hi kamuran,

    To get the selected rows try:

    IList rows = dg.SelectedItems;

    You should then be able to get to the column value from a row item.

    OR

    DataRowView row = (DataRowView)dg.SelectedItems[0];

    Then:

    row["ColumnName"];

    Best Regards
    Cathy

    Tuesday, January 24, 2017 5:50 AM