DataList with CompareValidator?

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
 
G

Guest

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;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top