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

RADGRID - Get values of row prior to the edited row

3 Answers 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prashanth
Top achievements
Rank 1
Prashanth asked on 03 Jul 2012, 06:17 AM
How can I get the values of all columns in a row that is previous to the current edited row? I can access the columns of the edited row, but I am not sure how to get the values of a specific row. When i am editing the grid for any particular row, I need to get the values of the immediate previous row. Can someone plese let me know?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Jul 2012, 06:44 AM
Hi,

Here the sample code for getting the value of the parent row in edit mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (e.Item.Edit)
        {
            TableCell cell = (TableCell)item["UniqueName"];   
            string value=cell.Text;
        }
    }
}

Thanks,
Shinu.
0
Prashanth
Top achievements
Rank 1
answered on 03 Jul 2012, 07:09 AM
Thanks for the respons. But here is my code and I have mentioned what I need in the IF ELSE LOOP:

 

protected void RadGrid4_UpdateCommand(object source, GridCommandEventArgs e) 

    if (e.Item is GridEditFormItem

    { 

        GridEditFormItem item = (GridEditFormItem)e.Item; 

        int updateCustId = Convert.ToInt32(item.GetDataKeyValue("TICKLER_ID"));

        if (updateCustId != 0) 

        { 

            RadDatePicker rdFinDt = ((RadDatePicker)item.FindControl("txtFinStmtDt"));           

            string sDaystoRecv = ((TextBox)item.FindControl("txtDaysRecv")).Text;;
            if (sTickItem == "RECEIVE FINANCIAL STATEMENTS"

            {

                rdDueDt.SelectedDate = rdFinDt.SelectedDate.Value.AddDays(Convert.ToDouble(sDaystoRecv));  

            }
            else
            {
                //Get date value in the previous row and add that to sDaystoRecv 
                //How to get value in the previous row?
            }
        }
    }
}

0
Shinu
Top achievements
Rank 2
answered on 05 Jul 2012, 04:26 AM
Hi,

Try the following code snippet to get the value of the previous row.

C#:
public static int index = 0;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem))
    {
        index = editedItem.ItemIndex;
        index = index - 1;
    }
}
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridDataItem item = (GridDataItem)RadGrid1.MasterTableView.Items[index];
    RadDatePicker datepicker = (RadDatePicker)item.FindControl("txtFinStmtDt");
    string date = datepicker.SelectedDate.ToString(); //date for the previous row
}

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