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.
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.