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

find textbox in Edit template

3 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 06 Jul 2013, 05:39 AM
Hi,

        I used the textbox in edit template for update the values in gridview. But I got the problem(Collection was modified; enumeration operation may not execute.) .Please give me the solution.

My Code behind code:

 protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridDataItem id = (e.Item as GridDataItem);
            string Empid = id.OwnerTableView.DataKeyValues[id.ItemIndex]["EmpId"].ToString();
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                TextBox txtleavetaken = (TextBox)item.FindControl("txttakenleave");
                TextBox txtleaveremain = (TextBox)item.FindControl("txtleavecount");
                TextBox txttotalworkdays = (TextBox)item.FindControl("txttotalworkdays");
                TextBox txtadvance = (TextBox)item.FindControl("txtadvance");
                TextBox txtbonus = (TextBox)item.FindControl("txtbonus");
                TextBox txtothers = (TextBox)item.FindControl("txtothers");
                TextBox txttotalsalary = (TextBox)item.FindControl("txttotalsalary");
                objpl.empname = Empid.ToString();
                objpl.takenleave = txtleavetaken.Text;
                objpl.leave = txtleaveremain.Text;
                objpl.totalworkdays = txttotalworkdays.Text;
                objpl.empadvance = txtadvance.Text;
                objpl.bonus = txtbonus.Text;
                objpl.empothers = txtothers.Text;
                objpl.totalsalary = txttotalsalary.Text;
                objbl.updatesalarydetail(objpl);
                fullviewstaff();
            }



Thanks,
Arun.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jul 2013, 05:45 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    GridEditFormItem item = (e.Item as GridEditFormItem);
    string Empid = item.GetDataKeyValue("EmpId").ToString();
    TextBox txtleavetaken = (TextBox)item.FindControl("txttakenleave");
}


Thanks,
Jayesh Goyani
0
Arun
Top achievements
Rank 1
answered on 06 Jul 2013, 06:06 AM
Hi Jayesh Goyani,

                         Thanks for Your code.But I tried this code already.In this, i am not able to reduce the width of textbox in edit mode.So it exceeds the size of gridview more compare to gridview in normal mode.Please give me the solution to reduce textbox width in edit mode.
Thanks,
Arun.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jul 2013, 06:22 AM
Hello,

To reduce the width of the any control in edit mode, we have to use ItemDataBound event.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
    {
        GridEditFormItem item = (e.Item as GridEditFormItem);
        string Empid = item.GetDataKeyValue("EmpId").ToString();
        TextBox txtleavetaken = (TextBox)item.FindControl("txttakenleave");
        txtleavetaken.Width = Unit.Pixel(100);
    }
}


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Arun
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Arun
Top achievements
Rank 1
Share this question
or