dynamic datagrid and validator

Discussion in 'ASP .Net Datagrid Control' started by aurelie, May 10, 2004.

  1. aurelie

    aurelie Guest

    Hello,

    I have a problem with one datagrid and a CompareValidator :

    I have a datagrid, filled with textbox, and a button. I expect integer
    in my textbox, so I want to test data before to process with a
    validator.
    I build my dategrid in a function called in the Page.Load().
    ----------------------------------------------------------------------------------
    TemplateColumn textBoxColumn = new TemplateColumn();
    textBoxColumn.HeaderText = "";
    MainDataGrid.Columns.Add(textBoxColumn);

    int j = 0;
    foreach(DataGridItem dgi in MainDataGrid.Items)
    {
    // TextBox Warning
    TextBox warningTextBox = new TextBox();
    warningTextBox.ID = "warningTextBox"+j;
    warningTextBox.Width = 50;
    warningTextBox.EnableViewState = true;
    dgi.Cells[0].Controls.Add(warningTextBox);

    // Validator
    CompareValidator warningValidator = new CompareValidator();
    warningValidator.ControlToValidate = warningTextBox.ID;
    warningValidator.Operator = ValidationCompareOperator.DataTypeCheck;
    warningValidator.Type = ValidationDataType.Integer;
    warningValidator.Text = "error";
    warningValidator.Display = ValidatorDisplay.Dynamic;
    warningValidator.ID = "warningValidator"+j;
    dgi.Cells[0].Controls.Add(warningValidator);
    j++;
    }
    ----------------------------------------------------------------------------------

    Next in the Button_Click(), I test data validity. But there is no
    message and the function isValid always equals to true.
    ----------------------------------------------------------------------------------

    CompareValidator warningValidator =
    (CompareValidator)MainDataGrid.Cells[0].Controls[1];
    if (warningValidator != null)
    {
    warningValidator.Validate();
    if (warningValidator.IsValid)
    {
    the next.....
    }
    }
    ----------------------------------------------------------------------------------

    If anyone have an idea ????
    Bests regards
    Aurélie
     
    aurelie, May 10, 2004
    #1
    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. coollzh
    Replies:
    0
    Views:
    381
    coollzh
    Jun 3, 2004
  2. Replies:
    4
    Views:
    905
    Richter~9.6
    Feb 13, 2007
  3. aurelie

    dynamic datagrid and validator

    aurelie, May 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    135
    aurelie
    May 10, 2004
  4. Replies:
    0
    Views:
    208
  5. aurelie

    dynamic datagrid and validator

    aurelie, May 10, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    96
    aurelie
    May 10, 2004
Loading...

Share This Page