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

Combobox Bind issue in grid while using custom template in editmode

5 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 27 Nov 2013, 06:18 AM
Hi,
I am facing Combobox Bind issue in grid while using custom template in editmode,
table data comes to datatable but while providing datasource it gives error.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem)
       {
           GridEditableItem edit = (GridEditableItem)e.Item;
           RadComboBox cmbUserType = (RadComboBox)edit.FindControl("cmbusertype");
           DataTable dt1 = ObjGlobas.UserType();
           cmbUserType.DataSource = dt1;
           cmbUserType.DataTextField = "UserType";
           cmbUserType.DataValueField = "UserTypeId";
           cmbUserType.DataBind();
       }
   }
Thanks

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 06:52 AM
Hi Swapnil,

I guess you want to bind the RadComboBox in editmode. Please use the following if condition when the Grid is in editmode:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
  if (e.Item is GridEditableItem && e.Item.IsInEditMode )
    {
      GridEditableItem edit = (GridEditableItem)e.Item;
      RadComboBox cmbUserType = (RadComboBox)edit.FindControl("cmbusertype");
      DataTable dt1 = ObjGlobas.UserType();
      cmbUserType.DataSource = dt1;
      cmbUserType.DataTextField = "UserType";
      cmbUserType.DataValueField = "UserTypeId";
      cmbUserType.DataBind();
    }
  }

Thanks,
Princy
0
Swapnil
Top achievements
Rank 1
answered on 27 Nov 2013, 07:13 AM
Hi,
i am using custom template for insert and automatic editmode for update
i want to bind the db output to combobox in custom template for insert(see attached images)
and datatable  also has value but during bind it gives error

Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 07:32 AM
Hi Swapnil,

Please use GridEditFormInsertItem, when the Grid is in Insert-mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditFormInsertItem)
  {
      GridEditFormInsertItem insert = (GridEditFormInsertItem)e.Item;
      //Your code
  }
}

Thanks,
Princy
0
Swapnil
Top achievements
Rank 1
answered on 27 Nov 2013, 08:00 AM
Thanks
but inside if condition only one combo fills up and it gives same error for second combo though the data can be seen in datatable.
Why this is happening?

0
Swapnil
Top achievements
Rank 1
answered on 27 Nov 2013, 08:13 AM
Solved it ,
i just used column name cmbCompanyName  rether than cmbcompanyname
Big Thanks To You
Thanks
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Share this question
or