DataList with CompareValidator?

  • Thread starter Thread starter Scott.Metzger
  • Start date Start date
S

Scott.Metzger

Hi,

I have a DataList and on the EditTemplaate I have a CompareValidator

I am using an Update_Command for the DataList.
The CompareValidator works fine and displays, however, the Update Command
still fires and attempts to execute the code in the procedure.

How do I check to see if the CompareValidator is 'active' or how do I keep
the Update Command from fireing?

<asp:DataList ID="listVetMed" runat="server" DataKeyField="eor_supplies_id"
DataSourceID="dsVetMed" BorderStyle="Solid"
OnEditCommand="Edit_Command"
OnCancelCommand="Cancel_Command"
OnDeleteCommand="Delete_Command"
OnUpdateCommand="Update_Command">
....

protected void Update_Command(object sender, DataListCommandEventArgs e)
{
DropDownList ddAnimalList =
(DropDownList)e.Item.FindControl("ddAnimalList");
string eor_supplies_id =
listVetMed.DataKeys[e.Item.ItemIndex].ToString();
Label lblcare_ts_id = (Label)e.Item.FindControl("lblcare_ts_id");
Label lblQuarantineTsId =
(Label)e.Item.FindControl("lblQuarantineTsId");
TextBox txtQty = (TextBox)e.Item.FindControl("txtQty");
DropDownList ddBSLLevel =
(DropDownList)e.Item.FindControl("ddBSLLevel");
DropDownList ddDateNeeded =
(DropDownList)e.Item.FindControl("ddDateNeeded");
TextBox txtNumDays = (TextBox)e.Item.FindControl("txtNumDays");


DBService.UpdateVetMedAnimalPurchase(lblFiscalYear.Text,
eor_supplies_id, lblcare_ts_id.Text,
lblQuarantineTsId.Text,
ddAnimalList.SelectedValue,
txtQty.Text,
ddBSLLevel.SelectedValue, ddDateNeeded.SelectedValue,
txtNumDays.Text);

listVetMed.ShowHeader = true;
listVetMed.EditItemIndex = -1;
listVetMed.DataBind();

}


Thanks,
Scott
 
Hi,

I have a DataList and on the EditTemplaate I have a CompareValidator

I am using an Update_Command for the DataList.  
The CompareValidator works fine and displays, however, the Update Command
still fires and attempts to execute the code in the procedure.

How do I check to see if the CompareValidator is 'active' or how do I keep
the Update Command from fireing?

<asp:DataList ID="listVetMed" runat="server" DataKeyField="eor_supplies_id"
DataSourceID="dsVetMed" BorderStyle="Solid"
     OnEditCommand="Edit_Command"
     OnCancelCommand="Cancel_Command"
     OnDeleteCommand="Delete_Command"
     OnUpdateCommand="Update_Command">
...

protected void Update_Command(object sender, DataListCommandEventArgs e)
    {
        DropDownList ddAnimalList =
(DropDownList)e.Item.FindControl("ddAnimalList");
        string eor_supplies_id =
listVetMed.DataKeys[e.Item.ItemIndex].ToString();
        Label lblcare_ts_id = (Label)e.Item.FindControl("lblcare_ts_id");
        Label lblQuarantineTsId =
(Label)e.Item.FindControl("lblQuarantineTsId");
        TextBox txtQty = (TextBox)e.Item.FindControl("txtQty");
        DropDownList ddBSLLevel =
(DropDownList)e.Item.FindControl("ddBSLLevel");
        DropDownList ddDateNeeded =
(DropDownList)e.Item.FindControl("ddDateNeeded");
        TextBox txtNumDays = (TextBox)e.Item.FindControl("txtNumDays");

        DBService.UpdateVetMedAnimalPurchase(lblFiscalYear.Text,
eor_supplies_id, lblcare_ts_id.Text,
                                            lblQuarantineTsId.Text,
ddAnimalList.SelectedValue,
                                            txtQty.Text,
ddBSLLevel.SelectedValue, ddDateNeeded.SelectedValue,
                                            txtNumDays.Text);

        listVetMed.ShowHeader = true;
        listVetMed.EditItemIndex = -1;
        listVetMed.DataBind();

    }

Thanks,
Scott

Add the following code to the start of the UpdateCommand event
handler:

if (!Page.IsValid)
return;
 
Back
Top