Validation Between Controls

Discussion in 'ASP .Net Datagrid Control' started by DS, Nov 17, 2005.

  1. DS

    DS Guest

    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, Nov 17, 2005
    #1
    1. Advertising

  2. DS

    Rick Guest

    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" <> escribió en el mensaje
    news:...
    >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, Nov 17, 2005
    #2
    1. Advertising

  3. DS

    Rick Guest

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

    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" <> escribió en el mensaje
    news:...
    >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, Nov 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,076
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    446
    Teemu Keiski
    Apr 10, 2004
  3. Alan Silver
    Replies:
    8
    Views:
    2,820
    Alan Silver
    Jan 24, 2005
  4. baroque Chou
    Replies:
    4
    Views:
    426
    Peter Blum
    Jan 24, 2006
  5. Bob D

    conflict between validation controls and "confirm"

    Bob D, Jan 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    132
    Teemu Keiski
    Jan 15, 2004
Loading...

Share This Page