473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CustomValidator inside Datagrid, DataList, DataRepeater

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

1. In the ItemTemplate, place your customvalidator
2. Set the OnServerValidate 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.

'=============Begin Code===================

<script runat="server">
Private Sub ValidateCustomValidator(ByVal source As System.Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)

Dim DataItem As DataListItem = CType(source,
CustomValidator).NamingContainer
Dim txt1 As TextBox = DataItem.FindControl("TextBox1")
Dim txt2 As TextBox = DataItem.FindControl("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:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="Cannot Be The Same"
OnServerValidate="ValidateCustomValidator">*</asp:CustomValidator>
</ItemTemplate>
</asp:DataList>

'=============End Code===================

Nov 19 '05 #1
0 3519

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

Similar topics

4
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
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,...
1
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...
0
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...
3
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...
0
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...
1
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 ...
7
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...
3
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.