从两个文本字段进行部分/过滤搜索以选择列表

时间:2018-08-09 04:49:16

标签: asp.net webforms controller crud

我在控制器中的代码

    public List<Addresses> Addresses_FindByPartialStreetAddress(string partialnumber, string partialstreet)
    {
        using (var context = new A09Context())
        {
            var results = context.Database.SqlQuery<Addresses>(
                        "Addresses_FindByPartialStreetAddress @number, @street",
                        new SqlParameter("number", partialnumber), new SqlParameter("street", partialstreet));
            return results.ToList();
        } 

我在Webform页面中的代码,我不确定如何从两个文本字段中实现部分搜索以提取列表的选择。.我知道我在这里做错了

   protected void SearchAddress_Click(object sender, EventArgs e)
{


    if (string.IsNullOrEmpty(SearchPartialNumber.Text))
    {
        errormsgs.Add("Enter a partial address number to search.");
        LoadMessageDisplay(errormsgs, "alert alert-info");
    }
    if (string.IsNullOrEmpty(SearchPartialStreet.Text))
    {
        errormsgs.Add("Enter a partial address street to search.");
        LoadMessageDisplay(errormsgs, "alert alert-info");
    }
    else
    {
        try
        {
            AddressesController sysmgr = new AddressesController();
            List<Addresses> info =     
               sysmgr.Addresses_FindByPartialStreetAddress              
               (SearchPartialNumber.Text + SearchPartialStreet);

            AddressSelectionList.DataSource = info;
            AddressSelectionList.DataBind();
        }

我这样绑定列表

          protected void BindAddressSelectionList()
    {

        try
        {

            AddressesController sysmgr = new AddressesController();
            List<Addresses> info = sysmgr.Addresses_List();
           // info.Sort((x, y) => x.Number.CompareTo(y.Number));
            AddressSelectionList.DataSource = info;
            AddressSelectionList.DataTextField = "street";
            AddressSelectionList.DataValueField = "number";
            AddressSelectionList.DataBind();
            AddressSelectionList.Items.Insert(0, "select ...");
        }`

Click here to see what the form looks like

0 个答案:

没有答案