Hello !
I needed a RadGrid with possibility to change data in it without pressing any Edit buttons, so i added textboxes and Save/Delete buttons directly to ItemTemplates, also added CommandItemDisplay="Top" to insert new rows, as a result RadGrid looks like this:
<telerik:RadGrid ID="gvwEducations" runat="server" GridLines="None" OnItemDataBound="gvwEducations_ItemDataBound"
AutoGenerateColumns="False" OnItemCommand="gvwEducations_ItemCommand">
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false" EditMode="InPlace">
<Columns>
<telerik:GridTemplateColumn UniqueName="IntstituteTemplate" HeaderText="Institute">
<ItemTemplate>
<telerik:RadComboBox ID="cbxInstitute" runat="server">
</telerik:RadComboBox>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="cbxInstitute" runat="server">
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="StartTimeTemplate" HeaderText="Start">
<ItemTemplate>
<telerik:RadTextBox ID="tbxStartYear" runat="server">
</telerik:RadTextBox>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox ID="tbxStartYear" runat="server">
</telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn CommandName="Save" Text="Save" UniqueName="SaveColumn"
ShowInEditForm="true">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
ShowInEditForm="true">
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Here comes the questions :)
is it possible to use ItemTemplate on item insert ?(at the moment edititemtemplate is just copypaste of itemtemplate)
and one more questions about codebehind :
protected void gvwEducations_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
RadComboBox cbxInstitute = (RadComboBox)e.Item.FindControl("cbxInstitute");
RadTextBox tbxStart = (RadTextBox)e.Item.FindControl("tbxStartYear");
cbxInstitute.DataSource = SomeCacheDatasource;
cbxInstitute.DataBind();
if (e.Item.DataItem is MyDataType)
{
//fill textboxes with data from datasource
}
}
if (e.Item is GridEditFormInsertItem) //if inserting new item, fill comboboxes
{
RadComboBox cbxInstitute = (RadComboBox)e.Item.FindControl("cbxInstitute");
cbxInstitute.DataSource = SomeCacheDatasource;
cbxInstitute.DataBind();
}
}
protected void gvwEducations_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Save")
{
SaveData(e);
}
}
when i save newly added item in gvwEducations_ItemCommand all it's controls values exist but they are empty,
am i doeing something wrong ?
Thank you !