Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
| Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 18th, 2003, 01:11 AM
Registered User
 
Join Date: Sep 2003
Location: Chennai, Tamil Nadu, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Controls Within custom validator control

There is a radiobuttonlist which has two options and a textbox control.
If I select one option from the radio button, the textbox control should not be empty.
But these two controls are in the ItemTemplate of DataGrid.
If I use the txtname in servervalidateEventargs, it gives the error 'Field not defined'.
If I use 'e.item.findcontrol("txtname")', it gives the errot 'Item is not in the servervalidateEventargs'

public sub checkEmpty(s as object,args as servervalidateEventargs)
    dim txtname as TextBox
    txtname=e.Item.findcontrol("TxtName1)
    If args.value=2 and txtname.text="" then
        args.isValid=false
        exit sub
    else
        args.isvalid=True
    end if
end sub

Please reply me.

Thanks.

  #2 (permalink)  
Old March 26th, 2005, 04:38 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I assume that your webform has a datagrid wherein each row has a radiobuttonlist with two options and a textbox. and there is submit button. When this button is clicked, the validation has to be performed.

When u hit the submit button, if one of the options in the radiobutton list is selected, the textbox shud not be empty.

U dont even have to use a custom validator. Because a custom validator only validates a particular control. In the validation function, if u only want to check a particular button is selected, u can do that if the controltovalidate of the validator is set to the radiobuttonlist. But in this function you cant get the textbox value because there is no reference to that particular item in the datagrid.

U can do the validation as follows on the submit button click (or whatever event in ur code)

  Dim dgi As DataGridItem
        For Each dgi In DataGrid1.Items
            If CType(dgi.FindControl("RadioButtonList1"), RadioButtonList).SelectedItem.Value = "1" And CType(dgi.FindControl("TextBox1"), TextBox).Text = String.Empty Then
                ErrorMessageLabel.text = "The textbox cannot be empty if Option 1 is selected"
                Exit Sub
            Else
                ErrorMessageLabel.text = String.Empty
                'Do the remaining tasks
            End If
        Next

Thanks
Pradeepa



Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Validator against a database Steve Spicer ASP.NET 2.0 Professional 16 January 12th, 2008 06:25 AM
User Control within Custom Server Controls www2004 ASP.NET 1.x and 2.0 Application Design 3 April 15th, 2005 09:00 AM
urgent custom control with collection of controls dd_smith Pro VB.NET 2002/2003 1 December 19th, 2004 06:05 PM
About Custom DataGrid control sharu56 General .NET 0 September 8th, 2004 05:01 AM
Custom Validator bmains ASP.NET 1.0 and 1.1 Basics 4 December 18th, 2003 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.