This is a migrated thread and some comments may be shown as answers.

RowIndex is not correct from GridButtonColumn

1 Answer 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Toxic
Top achievements
Rank 1
Toxic asked on 23 Jul 2011, 10:15 PM
This is strange. I have a radgrid with GridButtonColumn. The gridbuttoncolumn has a commandname of DeleteItem.

I pick this up on the server side in the Radgrid_Itemcommand sub. 

At this point I want to reference items in the grid to perform other functions. 

The code I have been using for an ID databound column (unique name mnu_3_id)

id =  radgrid1.Items.Item(e.Item.RowIndex)("mnu_3_id").Text

However, the rowindex that is returned is incorrect. It returns a number twice as big + 1. 

i.e. clicking row 0 results in a 2 being returned, row 1 a 4, row 2 a 6 etc.

I can obviously work around this, but why does it return the incorrect index?

Cheers

Tox

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2011, 07:16 AM
Hello Toxic,

You can access the GridButtonColumn from sever side and pass the index in Javascript.
aspx:
<telerik:GridButtonColumn Text="click" UniqueName="ColumnUniqueName"  ButtonType="LinkButton">
</telerik:GridButtonColumn>
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            LinkButton btn1 = (LinkButton)item["ColumnUniqueName"].Controls[0];
            btn1.Click += new EventHandler(btn1_Click);
            int index = item.ItemIndex;
            btn1.Attributes.Add("onclick", "clickEvent('" + index + "');");
        }
    }
JS:
<script type="text/javascript">
function clickEvent(index)
  {
    alert(index);
  }
</script>

Thanks,
Shinu.
Tags
Grid
Asked by
Toxic
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or