I am attempting to implement batch updating using controls that are located within the EditItemTemplate of a GridTemplate Column. I am currently using a OnPreRender event to set all datagrid columns to edit mode. The idea is the user should then be able to select values in a radcombobox and check box located in a GridTemplate column for each entry in the grid. After the users has made their edits to multiple rows in the grid they should be able to hit a single button to process all updates. I am attempting to use an approach similar to what is described in this article however I have been having difficulties with my OnItemCommand event as I have been unable to retrieve the values the radcombo box and check box in my EditItemTemplate have been set to.
Below is what I am attempting to do currently. Also I would like to remove the "update" and "cancel" links from the EditItemTemplate rather then set the text of the link to nothing in a OnItemCreated event as I am doing currently. Thanks in advance for helping out a Telerik beginner.
<
telerik:RadGrid ID="gridTestGrid" runat="server" AllowMultiRowEdit="True"
OnNeedDataSource
="gridTestGrid_DataSource"
OnItemDataBound
="gridTestGrid_ItemDataBound" OnPreRender="gridTestGrid_PreRender" OnItemCreated="gridTestGrid_ItemCreated" OnItemCommand="gridTestGrid_ItemCommand"
AutoGenerateColumns
="False" GridLines="Horizontal">
<
MasterTableView AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom" DataKeyNames="TestGridID">
<
CommandItemTemplate>
<
asp:Button ID="btnUpdate" runat="server" Text="Update Changes" />
</
CommandItemTemplate>
<
RowIndicatorColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
RowIndicatorColumn>
<
ExpandCollapseColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
ExpandCollapseColumn>
<
Columns>
......Some Other Columns .....
<
telerik:GridTemplateColumn HeaderText="Facility" Visible="false"
UniqueName
="rcbColumn">
<
ItemTemplate>
</
ItemTemplate>
<
EditItemTemplate>
<
telerik:RadComboBox ID="rcbFacility" runat="server" AllowCustomText="true" MarkFirstMatch="true" Width="300px" AppendDataBoundItems="true"></telerik:RadComboBox>     Send to IT?: <asp:CheckBox ID="ckBox" runat="server" Checked="false" />
</
EditItemTemplate>
</
telerik:GridTemplateColumn>
</
Columns>
</
MasterTableView>
protected
void gridTestGrid_ItemCreated(object source, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item is GridEditableItem && e.Item.IsInEditMode)
{
LinkButton
updateButton = (LinkButton)e.Item.FindControl("UpdateButton");
updateButton.Text =
"";
LinkButton
cancelButton = (LinkButton)e.Item.FindControl("CancelButton");
cancelButton.Text =
"";
}
}
protected
void gridTestGrid_PreRender(object source, EventArgs e)
{
foreach
(GridDataItem item in gridTestGrid.Items)
{
item.Edit =
true;
gridTestGrid.Rebind();
}
}
protected
void gridTestGrid_ItemCommand(object source, GridCommandEventArgs e)
{
Hashtable
newValues = new Hashtable();
foreach
(GridEditableItem editedItem in gridTestGrid.Items)
{
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
RadComboBox
combo = ((RadComboBox)editedItem["rcbColumn"].FindControl("rcbFacility"));
if
(combo != null)
{
string
selected = combo.SelectedItem.ToString();
}
}
}
8 Answers, 1 is accepted
Wow that formatting was messed up just a bit.... here is adding the code samples as a code block:
| <telerik:RadGrid ID="gridTestGrid" runat="server" AllowMultiRowEdit="True" |
| OnNeedDataSource="gridTestGrid_DataSource" |
| OnItemDataBound="gridTestGrid_ItemDataBound" OnPreRender="gridTestGrid_PreRender" OnItemCreated="gridTestGrid_ItemCreated" OnItemCommand="gridTestGrid_ItemCommand" |
| AutoGenerateColumns="False" GridLines="Horizontal"> |
| <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom" DataKeyNames="OrphanID"> |
| <CommandItemTemplate> |
| <asp:Button ID="btnUpdate" runat="server" Text="Update Changes" /> |
| </CommandItemTemplate> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| ... some columns ... |
| <telerik:GridTemplateColumn HeaderText="Facility" Visible="false" |
| UniqueName="rcbColumn"> |
| <ItemTemplate> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadComboBox ID="rcbFacility" runat="server" AllowCustomText="true" MarkFirstMatch="true" Width="300px" AppendDataBoundItems="true"></telerik:RadComboBox>     Send to IT?: <asp:CheckBox ID="ckSendToIT" runat="server" Checked="false" /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| <FilterMenu EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| </telerik:RadGrid> |
| protected void gridTestGrid_PreRender(object source, EventArgs e) |
| { |
| foreach (GridDataItem item in gridTestGrid.Items) |
| { |
| item.Edit = true; |
| gridTestGrid.Rebind(); |
| } |
| } |
| protected void gridTestGrid_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| Hashtable newValues = new Hashtable(); |
| foreach (GridEditableItem editedItem in gridTestGrid.Items) |
| { |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); |
| RadComboBox combo = ((RadComboBox)editedItem["rcbColumn"].FindControl("rcbFacility")); |
| if (combo != null) |
| { |
| string selected = combo.SelectedItem.ToString(); |
| } |
| } |
| } |
| protected void gridTestGrid_ItemCreated(object source, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| LinkButton updateButton = (LinkButton)e.Item.FindControl("UpdateButton"); |
| updateButton.Text = ""; |
| LinkButton cancelButton = (LinkButton)e.Item.FindControl("CancelButton"); |
| cancelButton.Text = ""; |
| } |
| } |
| protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
| { |
| Hashtable newValues = new Hashtable(); |
| if (e.CommandName == "UpdateAll") |
| { |
| foreach (GridEditableItem editedItem in RadGrid1.EditItems) |
| { |
| e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); |
| RadComboBox combo = (RadComboBox)((GridDataItem)editedItem).EditFormItem["Unique1"].FindControl("txtCompanyName"); |
| if (combo != null) |
| { |
| string selected = combo.SelectedItem.ToString(); |
| } |
| } |
| } |
| } |
| protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| LinkButton updateButton = (LinkButton)e.Item.FindControl("UpdateButton"); |
| updateButton.Visible = false; |
| LinkButton cancelButton = (LinkButton)e.Item.FindControl("CancelButton"); |
| cancelButton.Visible = false; |
| } |
| } |
Best regards,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
Thanks for the suggestion. However what I am running into now is when I set
EditMode
="InPlace" in my MasterTableView I get object reference is not set to an instance of an object in
gridOrphan_ItemCreated when setting the update and cancel buttons to false. When I comment these lines out just to get the grid to render it does appear however the GridTemplateColumn is not visible even when I added an ItemTemplate. Nothing appears to be in edit mode. I am still fooling around with this but any suggestions you have would be very helpful and greatly appreciated.
Visible="false" needed to be removed from the GridTemplateColumn to have it remain visible. One of those things that was too obvious to notice....
I added:
EditMode
="InPlace"
to my MasterTableView however the result is that rather then the contents of the <EditItemTemplate> appearing below the row of GridBoundColumns it is added to the end of the row. This is not the desired result as I want the dropdown to appear directly beneath the row of GridBoundColumns.
I have done some more searching and I found the following posts which seemed applicable however I have still not gotten this working:
http://www.telerik.com/community/forums/aspnet-ajax/grid/multi-add-and-multi-edit-for-grid.aspx
http://www.telerik.com/support/kb/aspnet-ajax/grid/using-raddatepicker-raddatetimepicker-as-editor-in-template-column-of-radgrid.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/radcombobox-in-gridtemplatecolumn.aspx
I am getting a little frustrated now. As is suggested in the 3rd thread "RadComboBox in GridTemplateColumn" I have changed my databinding of the RadComboBox from the ItemDataBound event to the itemcreated event however it is still not working.... However I am beginning to think that it is not my effort to call the selected value in the combo boxes that is the problem but instead how I am populating the combobox?
Any help is appreciated I am a telerik beginner who is running out of ideas.
Unfortunately I could not replicate the described issue. In my attempt to reproduce the depicted behavior I have created a test project which is attached to this forum thread. Feel free to examine it and use it as base for further development. You also can review this online demo devoted on the same matter.
Regards,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
| RadComboBox combo = ((GridDataItem)editedItem).EditFormItem["rcbColumn"].FindControl("rcbFacility") as RadComboBox; |
Thanks for the test project Georgi and all of your help!!
I am using the same scenario, that is when the user clicks on Add new records i want to hide insert/update/cancel buttons to make the saving customized in external asp button. i am trying to find the link button (for ex: Dim updateButton As LinkButton = DirectCast(e.Item.FindControl("UpdateButton"), LinkButton)) but it returns as nothing!! i need a solution ASAP .
Your help is really appreciated.
Thanks,
Omar
Try the following code to achieve your scenario.
VB:
Private Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted Then Dim insertButton As LinkButton = DirectCast(e.Item.FindControl("PerformInsertButton"), LinkButton) insertButton.Visible = False Dim cancelButton As LinkButton = DirectCast(e.Item.FindControl("CancelButton"), LinkButton) cancelButton.Visible = False End IfEnd SubThanks,
Shinu.