Professional Web Applications Themes

Validation Between Controls - ASP.NET Data Grid Control

I have a datagrid with several fields with textboxes and drop downs. I want to be able to validate the drop down field in one column to only be required if the textbox field in another column has data. Does anyone know how to do this? I tried to use the compare validator and the custom validator but can't figure out how to reference the control from the other column. Any help would be greatly appreciated. Thanks, Deidre...

  1. #1

    Default Validation Between Controls

    I have a datagrid with several fields with textboxes and drop downs. I
    want to be able to validate the drop down field in one column to only
    be required if the textbox field in another column has data. Does
    anyone know how to do this?
    I tried to use the compare validator and the custom validator but can't
    figure out how to reference the control from the other column.
    Any help would be greatly appreciated.
    Thanks,
    Deidre

    DS Guest

  2. #2

    Default Re: Validation Between Controls

    hi DS,i have the same situation
    i have a gridview with 6 cols, i need to validate col #3, so i used a
    rangevalidator control, but the min and max range is different for each row,
    so i need to change maxrange and minrange each time user select a row, i
    converted the col #3 in Templatefield and then add a Rangevalidator to
    validate its contents

    but i dont know how to reference the control because its inside col#3 and
    col#3 properties doesn't display any known control name (Rangevalidator)


    "DS" <dsweatmanbellsouth.net> escribió en el mensaje
    news:1132247813.756117.168800g43g2000cwa.googlegr oups.com...
    >I have a datagrid with several fields with textboxes and drop downs. I
    > want to be able to validate the drop down field in one column to only
    > be required if the textbox field in another column has data. Does
    > anyone know how to do this?
    > I tried to use the compare validator and the custom validator but can't
    > figure out how to reference the control from the other column.
    > Any help would be greatly appreciated.
    > Thanks,
    > Deidre
    >

    Rick Guest

  3. #3

    Default Re: Validation Between Controls

    i've solved it at last with help of Bug_Bugger at
    [url]http://forums.asp.net/1116631/ShowPost.aspx[/url]

    Bug_Bugger says:

    Implement RowDataBound event, in it use FindControl to locate the
    appropriate controls and set the values

    so i did this

    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    // Find control on page.


    RangeValidator myControl1 = (RangeValidator) e.Row.FindControl("RngVal");
    //RngVal is my control name

    //original code was Control myControl1 .... but i changed it to the control
    type i need, in this case RangeValidator

    if (myControl1 != null)

    {

    // Get control's parent.

    Control myControl2 = myControl1.Parent;

    myControl1.MaximumValue = "50"; // i changed this value

    myControl1.MinimumValue = "40"; // and this

    Response.Write("Parent of the text box is : " + myControl2.ID); // this text
    shows control's parent

    }

    else

    {

    Response.Write("Control not found");

    }

    }



    and works!!!!

    "DS" <dsweatmanbellsouth.net> escribió en el mensaje
    news:1132247813.756117.168800g43g2000cwa.googlegr oups.com...
    >I have a datagrid with several fields with textboxes and drop downs. I
    > want to be able to validate the drop down field in one column to only
    > be required if the textbox field in another column has data. Does
    > anyone know how to do this?
    > I tried to use the compare validator and the custom validator but can't
    > figure out how to reference the control from the other column.
    > Any help would be greatly appreciated.
    > Thanks,
    > Deidre
    >

    Rick Guest

Similar Threads

  1. BIG WARNING - validation controls appear to be ignored.
    By Andy Fish in forum ASP.NET Security
    Replies: 7
    Last Post: February 26th, 05:20 PM
  2. Validation Controls
    By Charles A. Lackman in forum ASP.NET General
    Replies: 4
    Last Post: October 9th, 01:47 PM
  3. Adding validation controls programmatically
    By D Sheldon in forum ASP.NET Building Controls
    Replies: 0
    Last Post: May 11th, 06:31 PM
  4. Validation on custom controls
    By msnews.microsoft.com in forum ASP.NET Building Controls
    Replies: 0
    Last Post: July 18th, 02:26 PM
  5. Validation Controls Postback
    By Rafael Veronezi in forum ASP.NET General
    Replies: 2
    Last Post: July 3rd, 01:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139