473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CustomValidator inside Datagrid, DataList, DataRepeater

This is how you use the customvalidator control in any INamingContaine r
interface control (Datagrid, DataList, DataRepeater, etc).

1. In the ItemTemplate, place your customvalidator
2. Set the OnServerValidat e property of the customvalidator
3. Get reference to the Data Item object
(For DataList is DataListItem, for DataGrid its DataGridItem)
4. Get reference to any controls needed for validation
5. Perform the validation

Below is an example, where the two textboxes inside the ItemTemplate of
a DataList control cannot have the same value.

'=============B egin Code=========== ========

<script runat="server">
Private Sub ValidateCustomV alidator(ByVal source As System.Object,
ByVal args As System.Web.UI.W ebControls.Serv erValidateEvent Args)

Dim DataItem As DataListItem = CType(source,
CustomValidator ).NamingContain er
Dim txt1 As TextBox = DataItem.FindCo ntrol("TextBox1 ")
Dim txt2 As TextBox = DataItem.FindCo ntrol("TextBox2 ")
If txt1.Text = txt2.Text Then
args.IsValid = False
End If
End Sub
</script>

<asp:DataList id="DataList1" runat="server">
<ItemTemplate >
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"> </asp:TextBox>
<asp:CustomVali dator id="CustomValid ator1" runat="server"
ErrorMessage="C annot Be The Same"
OnServerValidat e="ValidateCust omValidator">*</asp:CustomValid ator>
</ItemTemplate>
</asp:DataList>

'=============E nd Code=========== ========

Nov 19 '05 #1
0 3528

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2258
by: Moojjoo | last post by:
Ok fellow C# developers: How do creat an instance of an object inside a dataset or datagrid. Example I need to have a placeholder inside a dataset. Any help would be great.
2
2321
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last, Fax, Phone, Category). Put an Edit column at the end... Now what?! If you go into Edit mode -- you can only edit 5 cells -- not all the rest of...
1
3137
by: Mikkel Olsen | last post by:
Hi. I have a problem regarding to the DataGrid_ItemDataBound event. I cant run this event when my datagrid is inside a DataList. The ItemDataBound for DataList1 is working well, but it never raises the DataGrid1_ItemDataBound event. Thx.
0
1712
by: Renato Neves | last post by:
My problem is simple, i have a datalist control with some controls inside of EditTemplate (the problem is the same in the DataGrid). I want to have access to this controls, using javascript, but i can't. How can i do this? <Code> <script language="javascript"> document.getElementById('<%=txt1.ClientID %>').value='test';...
3
1848
by: philipl | last post by:
hi, i have a textbox in my edititemtemplate in my datagrid. I have created a customvalidator for it, when i update the row the appropiate function gets called to customvalidate but the problem is that the error message in my customvalidator does not get printed in the datagrid even though I have set the isvalid property in the server...
0
1106
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event of the UserControl, they would appear false(the default value) when inside the top level datagrid. Here's the walkthrough (tried to make it as...
1
1905
by: Nicky | last post by:
hi, all I have a asp.net page, and there is a DataGrid in it. I want show it like Header: ID, StartTime, EndTime....... 1 12:20 12:40 This is the job which is ........ 2 14:30 14:45 This is the second job ........ Here, each item contains two row.What is the best solution for this? Or I should not use...
7
17308
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work either! Does anyone know how can I make this work? Thanks in advance!
3
1617
by: rlogics | last post by:
Please provide me with information on how to use SQL database Paging in ASP.Net without using DataGrid,DataRepeater,DataList Etc. Just Plane Paging
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.