Can I Use RequiredFieldValidator inside a repeater ?

B

bhavesh

Hello,

I use a repeater to display "Name" and "Order". I hope that users can
change
the "Order" field from the browser. And, if they input invalid value
(such
as string) in the "Order" field, I hope the validator control can alert

them. Can I do this with repeater? Or I should use other webcontrol?


Thanks,
Simon


---------------------------------------------------------------------------­-

-------
<asp:repeater id="repeater1" runat="server">
<HeaderTemplate>
<table>
<TR class="gridHead">
<TD nowrap>Name</TD>
<TD nowrap>Order</TD>
</TR>
</HeaderTemplate>
<ItemTemplate>
<TR class="gridItem" valign="top">
<TD<%# DataBinder.Eval(Container.DataItem, "Name")
%></TD>
<TD>
<asp:textbox id="txtOrder" runat="server"
value="<%#
DataBinder.Eval(Container.DataItem, "Order") %>" />
<asp:RequiredFieldValidator ID="valOrder"
Runat="server"
ControlToValidate="txtOrder" ErrorMessage="Cannot be empty." />
</TD>
</TR>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<asp:repeater>
<asp:Button ID="btnSubmit" Runat="server" Text="Submit" />
 
S

Scott M.

Repeaters are read only interfaces and don't have a mechanism to switch them
from read only view into edit view (templates). If that is what you need,
you should consider a DataList or a DataGrid.

RequiredFieldValidators won't check the data to see if it is a string, it
will only check to see if there is *some* data. If you need the field to be
required AND you need it to be a specific data type, then you'll need 2
validators (a RequiredFieldValidator and a RangeValidator) associated with
the one input field.

Lastly, yes, you can nest validators inside of DataList and DataGrid
controls (as mentioned you wouldn't put them into Repeaters since repeaters
aren't for data input).


Hello,

I use a repeater to display "Name" and "Order". I hope that users can
change
the "Order" field from the browser. And, if they input invalid value
(such
as string) in the "Order" field, I hope the validator control can alert

them. Can I do this with repeater? Or I should use other webcontrol?


Thanks,
Simon


---------------------------------------------------------------------------­-

-------
<asp:repeater id="repeater1" runat="server">
<HeaderTemplate>
<table>
<TR class="gridHead">
<TD nowrap>Name</TD>
<TD nowrap>Order</TD>
</TR>
</HeaderTemplate>
<ItemTemplate>
<TR class="gridItem" valign="top">
<TD<%# DataBinder.Eval(Container.DataItem, "Name")
%></TD>
<TD>
<asp:textbox id="txtOrder" runat="server"
value="<%#
DataBinder.Eval(Container.DataItem, "Order") %>" />
<asp:RequiredFieldValidator ID="valOrder"
Runat="server"
ControlToValidate="txtOrder" ErrorMessage="Cannot be empty." />
</TD>
</TR>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<asp:repeater>
<asp:Button ID="btnSubmit" Runat="server" Text="Submit" />
 
B

bhavesh

THanks a lot dear Scott.

U solved my total confusion. its preety explaination.

thanks again a lot.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top