Hello,

I am having a gridview and a drop down list placed above it. Suppose my gridview has total 100 records in it. However, i the user wishes to see only 5 , he has to select 5 from the drop down list and the gridview should display only 5 records.

How to achieve this?? Please let me know...

wating for response..

Hello,

I am having a gridview and a drop down list placed above it. Suppose my gridview has total 100 records in it. However, i the user wishes to see only 5 , he has to select 5 from the drop down list and the gridview should display only 5 records.

How to achieve this?? Please let me know...

wating for response..

Add a button next to your dropdown list....then add the following code to the button's click event....

GridView1.PageSize = DropDownList1.SelectedValue

make sure your dropdown listItem has a ( value="#" property set otherwise the code above won't work.

Hey thanks for it...

I used jquery for this...and its working !!

SIR i want to add a number of data into a grid using a drop down list for example think of a shop a person buys a no of things the shopkeeper chooses the catagory from a drop down list and then chooses the product from the catagory andd then clicks add then again enter the new catagory and products and does it until he press buy button i have tried but it not getting possible plz help i am using asp.net sql server and asp.net

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace WebApplication1_Sample
{
    public partial class data_table_to_combo : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(@"Data Source=USER-PC;Initial Catalog=ASP;User Id=sa;Password=sa123");
        DataTable ds = new DataTable();
        string CATAGORYID;
        string productid;
                    
        protected void Page_Load(object sender, EventArgs e)
        {

           
          

        }
        protected void drplist1cat_SelectedIndex_Changed(object sender, EventArgs e)
        {
        
            //string CATAGORYID;
            CATAGORYID = drplist1cat.SelectedValue;
            SqlDataAdapter da = new SqlDataAdapter("SELECT PRODUCTID,PRODUCTNAME FROM PRODUCT WHERE CATAGORYID='"+CATAGORYID+"'",con);
            //DataSet ds = new DataSet();
            da.Fill(ds);
            Ddlproduct.DataSource = ds;
            Ddlproduct.DataTextField = "PRODUCTNAME";
            Ddlproduct.DataValueField = "PRODUCTID";
            Ddlproduct.DataBind();
           


        }
        protected void ddlproduct_SelectedIndex_Changed(object sender, EventArgs e)
        {
             CATAGORYID = drplist1cat.SelectedValue;
             productid = Ddlproduct.SelectedValue;
             SqlDataAdapter da = new SqlDataAdapter("SELECT PRODUCTID,PRODUCTNAME FROM PRODUCT WHERE CATAGORYID='" + CATAGORYID + "'AND PRODUCTID='"+productid+"'", con);
            
             da.Fill(ds);
             Ddlproduct.DataSource = ds;
             Ddlproduct.DataTextField = "PRODUCTNAME";
             Ddlproduct.DataValueField = "PRODUCTID";
             Ddlproduct.DataBind();
             
            
        }
        protected void btnadd_clicked(object sender, EventArgs e)
        {
            
            CATAGORYID = drplist1cat.SelectedValue;
            productid = Ddlproduct.SelectedValue;
            if ((CATAGORYID != null)||(productid!=null&&CATAGORYID!=null))
            {
                SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM PRODUCT  WHERE CATAGORYID='" + CATAGORYID + "'AND PRODUCTID='"+ productid +"'", con);
               
                ad.Fill(ds);
                dgvprductadd.DataSource = ds;
                dgvprductadd.DataBind();
                
            }
            DataRow dr = ds.NewRow();
            
            
            

        }
        protected void btnbuy_clicked(object sender, EventArgs e)
        {

        }
       
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.