When I click the Update link button the editform deosn't close but it updates the record with the grid. Appreciate any help
I am using the latest version of RadGrid and VS2008 beta. Appreciate any help.
Here is my Grid Definition
<telerik:RadGrid ID="rgContactNumber"
OnItemCommand="rgContactNumber_ItemCommand"
OnItemDataBound="rgContactNumber_ItemDataBound"
OnNeedDataSource="rgContactNumber_NeedDataSource"
OnUpdateCommand="rgContactNumber_UpdateCommand"
AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
AllowAutomaticInserts="true" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
EnableAJAX="True"
GridLines="Horizontal" runat="server" Width="98%"
EnableAJAXLoadingTemplate="False"
LoadingTemplateTransparency="0"
PageSize="5">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="False" />
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView Width="100%" GridLines="Horizontal" DataKeyNames="ContactID" PageSize="5"
AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom">
<CommandItemTemplate>
<table>
<tr>
<td width="30%">
<asp:LinkButton ID="btnAdd" Text="Add Contact Number" CommandName="InitInsert" runat="server"/>
</td>
</tr>
</table>
</CommandItemTemplate>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton"
UpdateImageUrl="../App_Themes/Default/DataEditingImages/Edit.gif"
CancelImageUrl="../App_Themes/Default/DataEditingImages/Cancel.gif">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="ContactId" Groupable="False" HeaderText="Contact Id"
UniqueName="ContactIdColumn" ReadOnly="True" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactValue" HeaderText="Phone Number"
SortExpression="ContactValue" UniqueName="ContactValue">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactSubType.Description" HeaderText="Contact Type"
SortExpression="ContactSubType.Description"
UniqueName="PhoneType" ReadOnly="true" Visible="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactDescription" HeaderText="Describe Other"
SortExpression="ContactDescription" UniqueName="ContactDescription"
Visible="false">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="IsPrimary" HeaderText="Primary"
UniqueName="Primary" Visible="true">
</telerik:GridCheckBoxColumn>
<telerik:GridDropDownColumn HeaderText="Phone Type" UniqueName="ddlPhoneType" Visible="false"
ListValueField="ContactSubTypeID"
ListTextField="Description"
DropDownControlType="DropDownList">
</telerik:GridDropDownColumn>
<telerik:GridButtonColumn ConfirmText="Are you sure you want to Delete this Contact?"
ButtonType="ImageButton"
ImageUrl="../App_Themes/Default/DataEditingImages/Delete.gif"
CommandName="Delete"
Text="Delete"
UniqueName="DeleteColumn">
<HeaderStyle Width="20px"/>
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;background:white;">
<tr>
<td colspan="2" style="font-size: small"><b>Contact Details</b></td>
</tr>
<tr>
<td>
<table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>Phone Number</td>
<td><asp:TextBox ID="txtContactValue" runat="server" Text='<%# Bind( "ContactValue" ) %>'/></td>
</tr>
<tr>
<td>Phone Type</td>
<td>
<asp:DropDownList ID="ddlPhoneType"
DataSourceID="odsContactSubTypes"
DataTextField="Description"
DataValueField="ContactSubtypeID"
runat="server"
AutoPostBack="true"
ShowToggleImage="True"
Width="150px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>Is Primary</td>
<td><asp:CheckBox ID="chkIsPrimary" runat="server"/></td>
</tr>
<tr>
<td>Describe Other</td>
<td><asp:TextBox ID="txtContactDescription" runat="server" Visible="false"/></td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server"
CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="btnCancel"
Text="Cancel"
runat="server"
CausesValidation="False"
CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Here ia the cide behind
protected void rgContactNumber_ItemCommand(object sender, GridCommandEventArgs e)
{
try
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
odsContactSubTypes.DataBind();
}
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
Contact _contact = new Contact();
ObjectManager.InitializeObject<Contact>(ref _contact);
if (this.ContactList_CP == null)
{
m_ContactList = CollateralPartyBLO.GetContactsByCustomer(this.CustomerID_CP);
}
GridEditableItem editedItem = e.Item as GridEditableItem;
e.Canceled = true;
rgContactNumber.MasterTableView.IsItemInserted = false;
_contact.ContactValue = (editedItem.FindControl("txtContactValue") as TextBox).Text;
_contact.ContactType = CollateralPartyBLO.GetContactTypeById(1);
//_contact.ContactSubtype.ContactSubtypeID = (editedItem.FindControl("ddlPhoneType") as DropDownList).SelectedIndex;
_contact.ContactSubtype = CollateralPartyBLO.GetContactSubTypeById(1);
m_ContactList.Add(_contact);
rgContactNumber.DataSource = m_ContactList;
rgContactNumber.Rebind();
}
if (e.CommandName == RadGrid.EditCommandName)
{
GridDataItem item = (GridDataItem)e.Item;
this.ContactID_Edit = GetIdFromEventArgs(e, "ContactID");
}
if (e.CommandName == RadGrid.UpdateCommandName)
{
Contact _contact = CollateralPartyBLO.GetContactById(this.ContactID_Edit);
GridEditableItem editedItem = e.Item as GridEditableItem;
e.Canceled = true;
int _index = this.ContactList_CP.IndexOf(_contact);
_contact.ContactValue = (editedItem.FindControl("txtContactValue") as TextBox).Text;
_contact.ContactType = CollateralPartyBLO.GetContactTypeById(1);
//_contact.ContactSubtype.ContactSubtypeID = (editedItem.FindControl("ddlPhoneType") as DropDownList).SelectedIndex;
_contact.ContactSubtype = CollateralPartyBLO.GetContactSubTypeById(1);
this.ContactList_CP[0] = _contact;
rgContactNumber.DataSource = this.ContactList_CP;
rgContactNumber.Rebind();
}
}
catch (Exception ex)
{
string str = ex.Message;
}
}