Click here to Skip to main content
15,889,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

               ddlCustCode.DataBind();
           }
        }
Posted
Updated 9-Oct-13 20:07pm
v2
Comments
Zafar Sultan 10-Oct-13 1:54am    
What do you mean by record whose value > 0? You can check that condition in your SP or SQL query. Or is there something else your question is pointing to? Please elaborate.
chitransh635 10-Oct-13 1:56am    
Please clarify Your question .
xibit89 10-Oct-13 2:03am    
there are 3 columns CustName, CustCode, Qty
the upper code bind the gridview with CustName and CustCode from database, OnSelectedItem it automatically generate the value into the Qty column from database.

I want to add condition there that the Qty column only shows the value which are greater than 0.
xibit89 10-Oct-13 1:59am    
there are 3 columns CustName, CustCode, Qty
the upper code bind the gridview with CustName and CustCode, OnSelectedItem it automatically generate the value into the Qty column.

I want to add condition there that the Qty column only shows the value which are greater than 0.
JoCodes 10-Oct-13 2:09am    
anyways you are fetching the QTy value from the database right? So whats stopping you from adding filtering/condition in the sql query.

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
 
Share this answer
 
Comments
xibit89 10-Oct-13 2:45am    
thanks chitransh635. It Worked!!
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
 
Share this answer
 
Comments
xibit89 10-Oct-13 2:09am    
i am not allowed to edit dataBase. what i have to use is in asp.net.\

Second it is stored Procedure. Not Table.
You can try using Generic list so that it can be filtered easily.

C#
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();
        }


C#
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900