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

[Solved] DataBind find an earlier row item

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 30 Mar 2014, 05:40 PM
During a DataBind, I'd like to access an earlier row to do conditional formatting.  I need help completing the following code:

protected void RadGridX_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (item["Name"].Text == "RowIWant")
        {
            foreach(string colName in colNames)
            {
                //get this value
                int thisValue = Convert.ToInt32(item[colname].Text);

                // get the value from the RowToCompare
                int earlierValue = ???

            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Apr 2014, 09:04 AM
Hi Scott,

Please try the following C# code snippet which works fine at my end.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (item["CustomerID"].Text == "HANAR")
        {
            int index = item.ItemIndex;//accessing the current index
            GridDataItem item1=RadGrid1.Items[index - 1]; // previous index
            string text = item1["CustomerID"].Text;//prevoius text
             
        }
    }
}

Thanks,
Shinu.
0
Scott
Top achievements
Rank 1
answered on 27 Jun 2014, 06:32 PM
Thank you, Shinu. That works.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Scott
Top achievements
Rank 1
Share this question
or