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

Using RadComboBox in GridTemplateColumn of RadGrid

2 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tuan anh
Top achievements
Rank 1
tuan anh asked on 10 Nov 2008, 08:55 AM
Hi all,

I'm writing a page use RadGrid. These are my code:

1. test.aspx
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" Width="97%" ShowFooter="True" OnNeedDataSource="RadGrid1_NeedDataSource" GridLines="None" Skin="WebBlue" AutoGenerateColumns="False">
                <MasterTableView CommandItemDisplay="Top" DataKeyNames="ItemID" EditMode="InPlace" Width="100%">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                            <ItemStyle CssClass="MyImageButton" Width="20px"/>
                        </telerik:GridEditCommandColumn>

                        <telerik:GridTemplateColumn HeaderText="ItemID" FooterText="Total items: " UniqueName="ItemID">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblItemID" Text='<%# Eval("ItemID") %>' Width="30px"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox ID="cboItemID" DataTextField="ItemID" DataValueField="ItemID"
                                    OnInit="RadComboBox1_Init"
                                    EnableLoadOnDemand="True" runat="server" Width="30px" Skin="Telerik">
                            </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridTemplateColumn HeaderText="Description" SortExpression="Description">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblDescription" Text='<%# Eval("Description") %>' Width="120px"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox runat="server" ID="txtDescription" Text='<%# Bind("Description") %>' Width="120px"/>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

 ......................
                    </Columns>
                 </MasterTableView>
         </telerik:RadGrid>
2. test.aspx.cs

public partial class test : Page
{
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = SetUpData();
    }

    protected void RadComboBox1_Init(object sender, EventArgs e)
    {
        RadComboBox comboBox = (RadComboBox)sender;
        comboBox.DataSource = SetUpData();
        comboBox.DataBind();
    }

    private List<ItemTest> SetUpData()
    {
        List<ItemTest> listTest = new List<ItemTest>();

        ItemTest test1 = new ItemTest();
        test1.ItemID = "1";
        test1.Description = "description1";
        listTest.Add(test1);

        ItemTest test2 = new ItemTest();
        test2.ItemID = "2";
        test2.Description = "description2";
        listTest.Add(test2);

        return listTest;
    }
}

internal class ItemTest
{
    private string itemID;
    private string description;

    public string ItemID
    {
        get { return itemID; }
        set { itemID = value; }
    }

    public string Description
    {
        get { return description; }
        set { description = value; }
    }
}



My problem is: my page display normal in list view, but when I want to add new record or edit current record, my combo box only display one value. It can't display anymore.

Any one can help me, please.

Thanks so much.

2 Answers, 1 is accepted

Sort by
0
tuan anh
Top achievements
Rank 1
answered on 10 Nov 2008, 10:21 AM
I'm sorry for disturb all of you. I have found solution in these article:

http://www.telerik.com/support/kb/aspnet-ajax/grid/using-radcombobox-as-editor-in-template-column-of-radgrid.aspx



0
tuan anh
Top achievements
Rank 1
answered on 10 Nov 2008, 11:09 AM
I have run example in this article, file: RadComboBoxInRadGridNET2.zip

http://www.telerik.com/support/kb/aspnet-ajax/grid/using-radcombobox-as-editor-in-template-column-of-radgrid.aspx

But combo box TitleOfCourtesy didn't activity.

Any one can help me solve this problem. Thanks.



Tags
Grid
Asked by
tuan anh
Top achievements
Rank 1
Answers by
tuan anh
Top achievements
Rank 1
Share this question
or