Custom range validation in datagrid

G

Guest

I have a simple datagrid that shows configuration properties as Name : Value
pairs. I want to be able to programmatically change the validation controls
that apply based on the name field of the row that the user tries to edit.

So for example if the table shows:

TimeToHold 5
TimeToProcess 50

I would like to set limits on the range validator for TimeToHold between 3
and 10 and for TimeToProcess between 45 and 60 say.

I can't seem to reference the validation controls that are part of an
EditItemTemplate from within my OnEditCommand handler. Is there a way to do
this?

The datagrid is defined like this in the aspx page:
<asp:datagrid ID="GridView1" runat="server"
AutoGenerateColumns="False" OnEditCommand="GridView1_EditCommand"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateColumn HeaderText="Name">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Value">
<ItemTemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Value") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EditValue" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Value") %>'></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1"
runat="server" ControlToValidate="EditValue"
EnableClientScript="False"
ErrorMessage="RangeValidator"></asp:RangeValidator>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit"
UpdateText="Update"></asp:EditCommandColumn>
</Columns>
</asp:datagrid>


Thanks,

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top