Hi,
I encounter a problem that i use template edit form of grid, but in the edit form, the textbox value never be updated, always keep the old value. Can you help me find why this happen? Please see the bold fonts.
Front code:
<telerik:RadGrid ID="RadGridQuestionTable" runat="server" AllowFilteringByColumn="false"
OnItemCommand="RadGridQuestionTable_ItemCommand" CssClass="contenttable" Width="100%"
AllowPaging="True" AllowSorting="True" PageSize="10" ShowFooter="true" AutoGenerateColumns="False"
Skin="Office2007" GridLines="None" ShowGroupPanel="False" EnableHeaderContextMenu="False"
OnNeedDataSource="RadGridQuestionTable_NeedDataSource" >
<ClientSettings AllowColumnHide="False" AllowColumnsReorder="True" AllowDragToGroup="False">
</ClientSettings>
<MasterTableView EnableViewState="false" DataKeyNames="ID" EditMode="PopUp">
<Columns>
<telerik:GridBoundColumn DataField="SectionID" HeaderText="" UniqueName="SectionID"
ItemStyle-Width="20px" Display="false">
<ItemStyle Width="20px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Title" HeaderText="Question" UniqueName="Question"
ItemStyle-Width="200px">
<ItemStyle Width="200px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridButtonColumn Text="<img src='../Resource/images/edit.gif' border=0>"
CommandName="Edit" ButtonType="LinkButton" UniqueName="myEditColumn">
<ItemStyle HorizontalAlign="Center" Width="50px"></ItemStyle>
</telerik:GridButtonColumn>
<telerik:GridButtonColumn Text="<img src='../Resource/images/delete.gif' border=0>"
ConfirmText="Are you sure to delete this Question?" UniqueName="columnDelete"
CommandName="Delete" ButtonType="LinkButton" HeaderText="" ItemStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="50px"></ItemStyle>
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit Question: {0}"
CaptionDataField="Title" EditFormType="Template">
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<telerik:RadTextBox ID="EditTitleTxt" runat="server"
Text='<%# Bind( "Title") %>'
Skin="Office2007">
</telerik:RadTextBox>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="right">
<asp:Button ID="Button1" Text="Update"
runat="server" CommandName="Update">
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Office2007">
</HeaderContextMenu>
</telerik:RadGrid>
Back-end Code:
protected void RadGridQuestionTable_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int id = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
try
{
PPHGAuditQuestion questionObj = questionRespository.FindSingle((PPHGAuditQuestion s) => s.ID == id);
questionRespository.Delete(questionObj);
questionRespository.SaveChanges();
RadGridQuestionTable.DataSource = BindGrid(TemplateRadTreeView.SelectedNode == null ? 0 : int.Parse(TemplateRadTreeView.SelectedNode.Value));
RadGridQuestionTable.DataBind();
}
catch
{
questionRespository.ClearChanges();
}
}
else if (e.CommandName == "Update")
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string title = (editedItem.FindControl("EditTitleTxt") as RadTextBox).Text; // I also debug to here, the value always keep the old value.
int id = int.Parse(e.CommandArgument.ToString());
try
{
PPHGAuditQuestion questionObj = questionRespository.FindSingle((PPHGAuditQuestion s) => s.ID == id);
questionObj.Title = title;
questionObj.ModifiedBy = "";
questionObj.DateModified = DateTime.Now;
questionRespository.UpdateOrCreate(questionObj);
questionRespository.SaveChanges();
RadGridQuestionTable.DataSource = BindGrid(TemplateRadTreeView.SelectedNode == null ? 0 : int.Parse(TemplateRadTreeView.SelectedNode.Value));
RadGridQuestionTable.DataBind();
}
catch
{
questionRespository.ClearChanges();
}
}
}
I encounter a problem that i use template edit form of grid, but in the edit form, the textbox value never be updated, always keep the old value. Can you help me find why this happen? Please see the bold fonts.
Front code:
<telerik:RadGrid ID="RadGridQuestionTable" runat="server" AllowFilteringByColumn="false"
OnItemCommand="RadGridQuestionTable_ItemCommand" CssClass="contenttable" Width="100%"
AllowPaging="True" AllowSorting="True" PageSize="10" ShowFooter="true" AutoGenerateColumns="False"
Skin="Office2007" GridLines="None" ShowGroupPanel="False" EnableHeaderContextMenu="False"
OnNeedDataSource="RadGridQuestionTable_NeedDataSource" >
<ClientSettings AllowColumnHide="False" AllowColumnsReorder="True" AllowDragToGroup="False">
</ClientSettings>
<MasterTableView EnableViewState="false" DataKeyNames="ID" EditMode="PopUp">
<Columns>
<telerik:GridBoundColumn DataField="SectionID" HeaderText="" UniqueName="SectionID"
ItemStyle-Width="20px" Display="false">
<ItemStyle Width="20px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Title" HeaderText="Question" UniqueName="Question"
ItemStyle-Width="200px">
<ItemStyle Width="200px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridButtonColumn Text="<img src='../Resource/images/edit.gif' border=0>"
CommandName="Edit" ButtonType="LinkButton" UniqueName="myEditColumn">
<ItemStyle HorizontalAlign="Center" Width="50px"></ItemStyle>
</telerik:GridButtonColumn>
<telerik:GridButtonColumn Text="<img src='../Resource/images/delete.gif' border=0>"
ConfirmText="Are you sure to delete this Question?" UniqueName="columnDelete"
CommandName="Delete" ButtonType="LinkButton" HeaderText="" ItemStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="50px"></ItemStyle>
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit Question: {0}"
CaptionDataField="Title" EditFormType="Template">
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<telerik:RadTextBox ID="EditTitleTxt" runat="server"
Text='<%# Bind( "Title") %>'
Skin="Office2007">
</telerik:RadTextBox>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="right">
<asp:Button ID="Button1" Text="Update"
runat="server" CommandName="Update">
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Office2007">
</HeaderContextMenu>
</telerik:RadGrid>
Back-end Code:
protected void RadGridQuestionTable_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int id = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
try
{
PPHGAuditQuestion questionObj = questionRespository.FindSingle((PPHGAuditQuestion s) => s.ID == id);
questionRespository.Delete(questionObj);
questionRespository.SaveChanges();
RadGridQuestionTable.DataSource = BindGrid(TemplateRadTreeView.SelectedNode == null ? 0 : int.Parse(TemplateRadTreeView.SelectedNode.Value));
RadGridQuestionTable.DataBind();
}
catch
{
questionRespository.ClearChanges();
}
}
else if (e.CommandName == "Update")
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string title = (editedItem.FindControl("EditTitleTxt") as RadTextBox).Text; // I also debug to here, the value always keep the old value.
int id = int.Parse(e.CommandArgument.ToString());
try
{
PPHGAuditQuestion questionObj = questionRespository.FindSingle((PPHGAuditQuestion s) => s.ID == id);
questionObj.Title = title;
questionObj.ModifiedBy = "";
questionObj.DateModified = DateTime.Now;
questionRespository.UpdateOrCreate(questionObj);
questionRespository.SaveChanges();
RadGridQuestionTable.DataSource = BindGrid(TemplateRadTreeView.SelectedNode == null ? 0 : int.Parse(TemplateRadTreeView.SelectedNode.Value));
RadGridQuestionTable.DataBind();
}
catch
{
questionRespository.ClearChanges();
}
}
}