2

I am struggling to add a ComboBox inside my RadGrid while Inserting/Updating my grid. So when my grid goes into editmode I want a ComboBox to be displayed.

Here is my aspx page:

<telerik:radgrid id="radManageMembers" runat="server" cssclass="GridView" width="96%"
    autogeneratecolumns="true" onUpdateCommand="radManageMembers_UpdateCommand" Skin="WebBlue"
    onNeedDataSource="radManageMembers_NeedDataSource" OnDeleteCommand="radManageMembers_DeleteCommand"
    OnInsertCommand="radManageMembers_InsertCommand" OnItemCreated="radManageMembers_ItemCreated" OnItemCommand="radManageMembers_ItemCommand">
    <MasterTableView EditMode="InPlace" AutoGenerateColumns="false"
        TableLayout="Fixed" DataKeyNames="MemberID" CommandItemDisplay="TopAndBottom" Skin="WebBlue">
        <Columns>

            <telerik:GridBoundColumn DataField="MemberID" Display="false">
            </telerik:GridBoundColumn>

            <telerik:GridButtonColumn UniqueName="DeleteColumn" CommandName="Delete" ButtonType="PushButton" Text="Delete">
            </telerik:GridButtonColumn>

            <telerik:GridBoundColumn DataField="MemberName" UniqueName="MemberName" HeaderText="MemberName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="FirstName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="LastName" >
            </telerik:GridBoundColumn>                
            <telerik:GridBoundColumn DataField="Title" UniqueName="Title" HeaderText="Title">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AdditionalNumber" UniqueName="AdditionalNumber" HeaderText="AdditionalNumber">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Telephone" UniqueName="Telephone" HeaderText="Telephone">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="IDNumber" UniqueName="IDNumber" HeaderText="IDNumber">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="BusinessName" UniqueName="BusinessName" HeaderText="BusinessName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Email" UniqueName="Email" HeaderText="Email">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="LanguageCode" UniqueName="LanguageCode" HeaderText="LanguageCode">
            </telerik:GridBoundColumn>     

            <telerik:GridEditCommandColumn ButtonType="PushButton" UniqueName="EditCommandColumn">
                <HeaderStyle Width="85px"></HeaderStyle>
            </telerik:GridEditCommandColumn>

        </Columns>
            <EditFormSettings CaptionFormatString="Edit details for employee with ID {0}" CaptionDataField="EmployeeID">
            <FormTableItemStyle Width="100%" Height="29px"></FormTableItemStyle>
            <FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
            <FormStyle Width="100%"></FormStyle>
            <EditColumn ButtonType="ImageButton">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
    </ClientSettings>

I know you have to use the ItemCreated event but I can't get it to work exactly.

This is what I have in the ItemCreate, but this code doesn't work:

if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridCommandItem)
{
      GridCommandItem insertItem = (GridCommandItem)e.Item;
      RadComboBox combo = (RadComboBox)insertItem.FindControl("Title");
}

I have had a look at the example here - http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx

But this ComboBox does not populate distinct values from the database, there seems to be duplicates which I find pointless in a ComboBox.

I am open to see if there are alternative ways of doing this or the correct way of solving this problem.

Edit

The values for the ComboBox are from a database and all values are unique.

DanM7
  • 2,203
  • 3
  • 28
  • 46
SpaceApple
  • 1,309
  • 1
  • 24
  • 46
  • have you looked at the Telerik site there are so many awesome examples. I am surprised you have not looked at the ComboBox examples inside a Gridview that they have posted on their site – MethodMan Mar 08 '13 at 08:35
  • I have had a look at it, and there are some pretty cool examples. But I have not come across an example that suits this requirement, unless I am looking through a wall. – SpaceApple Mar 08 '13 at 08:37
  • Where is the combo box?? Where is the code to bind the combo box? – Brian Mains Mar 08 '13 at 17:52

1 Answers1

0

In your code you are not adding Combobox. So please add combobox in EditItemTemplate and try the following code to access the combobox

protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
            GridEditableItem item = (GridEditableItem)e.Item;
            RadComboBox combo = ((RadComboBox)item.FindControl("RadComboBoxValore"));
            combo.DataSource = SqlDataSource2;
            combo.DataValueField = "EmployeeID";
            combo.DataTextField = "EmployeeID";
            combo.DataBind();   
        }
    }

OR add GridDropDownColumn

Saritha.S.R
  • 800
  • 1
  • 6
  • 19