0

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..

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by rath.avinash
0

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.

0

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)
        {

        }
       
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.