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

editformate problem

4 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shanker bangari
Top achievements
Rank 1
shanker bangari asked on 20 Mar 2010, 07:56 AM
Hi,

this is shanker am doing application my requirement is catch the databound value in Itemdatabound event in GridEditable mode I am write this code 

protected void fulldaygrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            int? student_absence_id = null;

            if ((e.Item is GridEditableItem || e.Item is GridDataItem) && e.Item.IsInEditMode)
            {



                GridEditableItem editedItem = (GridEditableItem)e.Item;
                int item = editedItem.ItemIndex - 1;
                    student_absence_id = editedItem.OwnerTableView.Items[item].Cells[1].ToString().GetInteger();
                    //int? eventId = GetEventId(e.Item);
                    if (student_absence_id.HasValue)
                    {
                        var det = studentattendancemanager.sch_view_student_absence_single_day_detail(student_absence_id);



                        //Label lblStudentname = e.Item.FindControl("lblStudentname") as Label;
                        //if (lblStudentname != null)
                        //{
                        //    string Name = det.first_name + det.last_name;
                        //    lblStudentname.Text = Name;
                        //}
                        //Label lblStudentNumber = e.Item.FindControl("lblStudentNumber") as Label;
                        //if (lblStudentNumber != null)
                        //{
                        //    lblStudentNumber.Text = det.student_number;
                        //}

                        TextBox txtDescription = e.Item.FindControl("txtDescription") as TextBox;
                        if (txtDescription != null)
                        {
                            txtDescription.Text = det.description;
                      }


                }   
            }
        }

it's not working i am face this error 
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

thanks and regards
shanker.B

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 24 Mar 2010, 12:20 PM
Hello shanker,

If the field name you need to get is called student_absence_id and it is added to the DataKeyNames of the respective GridTableView, you can use:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        int student_absence_id = (int)item.GetDataKeyValue("student_absence_id");
    }
}

Alternatively, you can get the column editor using the column unique name:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("student_absence_id");
        int student_absence_id = Int32.Parse(editor.Text);
    }
}


Sincerely yours,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
shanker bangari
Top achievements
Rank 1
answered on 26 Mar 2010, 01:22 PM
Hi,

thank you for your response .But not working your solution this column my column is in visible and read only and out get the null val;ue of datakey value 


<telerik:GridBoundColumn DataField="student_absence_id" DataType="System.Int32" HeaderText="ID"
                    SortExpression="student_absence_id" UniqueName="student_absence_id" Visible="false" ReadOnly="true" >

thanks and regards 
shanker.B
                </telerik:GridBoundColumn>
0
Princy
Top achievements
Rank 2
answered on 26 Mar 2010, 01:58 PM

Hello Shanker,

Have you set the 'DataKeyNames' property as your field 'student_absence_id' in MasterTableView?

ASPX:

 
 <MasterTableView DataKeyNames="student_absence_id" DataSourceID="SqlDataSource1" .. 

Thanks,

Princy.

0
shanker bangari
Top achievements
Rank 1
answered on 26 Mar 2010, 02:42 PM
hi


thanks for response but my column is also accept null value i.if it,s null i get error object reference .how to solve that

thanks and regards
shanker.B
Tags
Grid
Asked by
shanker bangari
Top achievements
Rank 1
Answers by
Veli
Telerik team
shanker bangari
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or