This is a migrated thread and some comments may be shown as answers.

Require a new comment in Template Column

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 18 Dec 2013, 08:18 PM
I have a requirement when an item is updated in my radgrid for a descriptive comment to be added to that item.  I've added a Required Field Validator to a GridTemplateColumn and it works if this update is the first update of that item and the comment field is empty.  However, if someone has updated the item before, it views the previous comment as making the field valid and doesn't fire.  This is that code
<telerik:GridTemplateColumn DataField="Comments" FilterControlAltText="Filter column13 column"  AllowFiltering="false"<br>                            HeaderText="Comments" UniqueName="Comments"><br>                            <EditItemTemplate><br>                                <asp:TextBox ID="tbComments" runat="server" TextMode="MultiLine" Text='<%# Eval("Comments") %>'>></asp:TextBox><br>                                <asp:RequiredFieldValidator ID="rfvComments" ControlToValidate="tbComments" Display="Dynamic"<br>                                    runat="server" ErrorMessage="Please enter a reason for changing this budget item."></asp:RequiredFieldValidator><br>                            </EditItemTemplate><br>                            <ItemTemplate><br>                                <asp:Label ID="CommentsLabel" runat="server" Text='<%# Eval("Comments") %>'></asp:Label><br>                            </ItemTemplate><br>                        </telerik:GridTemplateColumn>

I also tried deleting the <%# Eval("Comments") > from the Text field and replacing it with "".  That blanks out the previous text and forces a new comment, but the new comment data is not returned to be entered in the database.  (Sql profiler shows NULL for that parameter).

So,  I'd appreciate any help in requiring a new unique comment for subsequent updates.
Thanks
Rick

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Dec 2013, 07:57 AM
Hi Rick,

From your code i guess you always want to show a message for the comments column. You can avoid the Text property of the TextBox, hence the Required Field Validator will be raised where necessary. On the UpdateCommand event the entered value can be captured.

ASPX:
<EditItemTemplate>
   <asp:TextBox ID="tbComments" runat="server" TextMode="MultiLine"></asp:TextBox>
   <asp:RequiredFieldValidator ID="rfvComments" ControlToValidate="tbComments" Display="Dynamic" runat="server" ErrorMessage="Please enter a reason for changing this budget item."></asp:RequiredFieldValidator>
</EditItemTemplate>

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
  if (e.Item is GridEditableItem)
  {
      GridEditableItem edit = (GridEditableItem)e.Item;
      TextBox txt = (TextBox)edit.FindControl("tbComments");
      string value = txt.Text;// Get the value here
  }
}

Thanks,
Princy
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or