选择值> GridView ASP.NET中为0

人气:766 发布:2022-09-22 标签: asp.net ASP.NET

问题描述

在这个数据绑定数据从GridBase到GridView DropDownList 它显示80个记录 我想使用条件选择那个值为>的记录0 任何想法如何完成

In this i m Binding Data From dataBase to GridView DropDownList it shows 80 records i want to use a condition it in that select that record whose value is > 0 any ideas how it can be done

private void bindCombo(string ddlName)
        {
               if (ddlName == "ddlCustCode")
           {
               ddlCustCode.DataSource = dl.getCustCode("S");
               ddlCustCode.DataTextField = "CardCode";
               ddlCustCode.DataValueField = "CardName";

               ddlCustCode.DataBind();
           }
        }

推荐答案

你可以这样做 你正在取材数据表中的数据 假设您正在获取数据表名称dt 创建数据表名称myNewTable DataTable myNewTable = dt.Select(qty<>'0')。CopyToDataTable(); 尝试一下,让我知道这对你有帮助而不做任何事更改数据库 You Can do like this You are fetching your data in datatable Suppose you are fetching your datatable name dt create ne datatable name myNewTable DataTable myNewTable = dt.Select("qty<> '0'").CopyToDataTable(); try it and let me know this will help you without making any changes in database

在数据库中你可以做 声明@quantity int set @quantity =从表格中选择数量> 0 如果@ quantity> 0 开始 从表格中选择CustName,CustCode,qty 结束 尝试这个让我知道 in database you can do declare @quantity int set @quantity=select quantity from table where quantity>0 if @quantity>0 begin select CustName,CustCode,qty from table end try this and let me know

您可以尝试使用Generic list以便它可以很容易过滤。 You can try using Generic list so that it can be filtered easily.
private void Bind()
        {
            List<Item> items = new List<Item>()
            {
                 new Item(){ Cust = "One", QTY=8 },
                 new Item(){ Cust = "Two", QTY=0},
                 new Item(){ Cust = "Three", QTY=14 }
            };//Adding list item just to demonstrate

            DropDownList1.DataSource = items.Where(itm=>itm.QTY>0) ;
            DropDownList1.DataTextField = "Cust";
            DropDownList1.DataValueField = "Cust";
            DropDownList1.DataBind();
        }

public class Item// this can be replaced as per your type that you fetch from your DL layer ( like dl.getCustCode("S") )
   {
       public string Cust { get; set; }
       public int QTY { get; set; }
   }

希望这有帮助

Hope this helps

422