3
Answers

Drop down validation in asp.net

rachayita jaiswal

rachayita jaiswal

11y
1.2k
1
Hi,

I have created validation for drop down - 

<asp:DropDownList ID="ddl_assetVendor" runat="server" Width="200px">
                                                                                                            </asp:DropDownList>
                                                                                                            <asp:RequiredFieldValidator ID="RFV_assetvendor" runat="server"  ControlToValidate="ddl_assetVendor" InitialValue="--Select Vendor--" ErrorMessage="Select Vendor Name!" Display="Dynamic" SetFocusOnError="true" >
                                                                                                            </asp:RequiredFieldValidator>

Drop down values are coming from data base.
so function for load data in drop down is - 

public void GetVendorName()
    {
        try
        {
            string ddlquery = "Select id,VendorName from m_vendor";
            dt = obj_db.GetCommonDataByQuesry(ddlquery);
            ddl_assetVendor.DataSource = dt;
            ddl_assetVendor.DataBind();
            ddl_assetVendor.DataTextField = "VendorName";
            ddl_assetVendor.DataValueField = "id";
            ddl_assetVendor.DataBind();
            ddl_assetVendor.Items.Insert(0, new ListItem("--Select Vendor--", "0"));
        }
        catch (Exception ex)
        {
            GetErrorFile("GetAssetLocaion", ex.Message);
        }
    }

No my Initial value will be = --Select Vendor-- right.
 But my drop down validation is not working .
Please tell is there any issue in my code?

Answers (3)