Asp.net modules
  • Home
  • c# Modules
  • Web Design
    • Html
    • Css
    • Java Script
  • Bootstrap
  • Sql
    • Queries
    • Stored Procedures
  • About Me
    • About Myself
    • My Projects
    • My Resume
  • Photo Gallery

Saturday, September 26, 2015

How to find results by click on dropdownlist selected value into a grid view?

 Unknown     6:37 AM     Asp.net     No comments   

Hi Friends... 


Here I explain full procedure of showing result on the selected value of dropdown in a grid view step by step on the onclick event.


Step 1: create a connection string in web.config  page


 <connectionStrings>
    <add name="conn" providerName="System.Data.SqlClient"
    connectionString="Data Source=Sk-Pc;uid=sa;pwd=12345;database=droplist"></add>
  </connectionStrings>



Step 2: create database  


Firstly  create a database and give it a name after then create a table I give it  UserDetail name and keep them allow null and auto increment the ID column.  





Step 3: HTML Design code goes here



<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title></title>
    <style type="text/css">
        .p {
            padding: 55px 55px 55px 55px;
        }
    </style>

</head>

<body>

    <form id="form1" runat="server">

        <div style="border: 2px groove #249fa3; height: 128px; width: 193px;" class="p">

            <asp:DropDownList ID="DropDownList1" runat="server"
                OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Font-Overline="False" Height="31px" Width="102px">
            </asp:DropDownList>

            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

            <br />

            <br />

            <asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click1" BackColor="#249fa3" Font-Bold="True" ForeColor="White" Width="108px" Height="39px" />

            <br />

            <br />

            <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#249fa3"
                BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">

                <AlternatingRowStyle BackColor="#249fa3" />

                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

                <HeaderStyle BackColor="#249fa3" Font-Bold="True" ForeColor="White" />

                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

                <SelectedRowStyle BackColor="#249fa3" Font-Bold="True" ForeColor="White" />

                <SortedAscendingCellStyle BackColor="#F1F1F1" />

                <SortedAscendingHeaderStyle BackColor="#0000A9" />

                <SortedDescendingCellStyle BackColor="#CAC9C9" />

                <SortedDescendingHeaderStyle BackColor="#000065" />

            </asp:GridView>

        </div>

    </form>

</body>

</html>



Step 4: Add some header files


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;



Step 5:   c# page code goes here



public partial class droplist : System.Web.UI.Page
{

    string str = ("Data Source=Sheetal;Initial Catalog=droplist;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection(str);

            string com = "Select * from UserDetail";

            SqlDataAdapter adpt = new SqlDataAdapter(com, con);

            DataTable dt = new DataTable();

            adpt.Fill(dt);

            DropDownList1.DataSource = dt;

            DropDownList1.DataBind();

            DropDownList1.DataTextField = "Name";

            DropDownList1.DataValueField = "ID";

            DropDownList1.DataBind();

        }
    }

    protected void Button1_Click1(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(str);

        SqlCommand cmd = new SqlCommand("select * from UserDetail where id = '" + DropDownList1.SelectedValue + "'", con);

        SqlDataAdapter Adpt = new SqlDataAdapter(cmd);

        DataTable dt = new DataTable();

        Adpt.Fill(dt);

        GridView1.DataSource = dt;

        GridView1.DataBind();

        Label1.Text = "record found";
        
    }

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



Demo :











  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • Asp.net insert, Edit, update, delete in grid view
    Introduction :   Here I explain how to insert, edit, update and delete data in grid view using asp.net. In this project I use so...
  • Angular Expressions
    Intoduction :-   Hii Friends... Today I explain about angular js expressions. this is similar to JavaScript expressions. 1) The expr...
  • Basic of css.
    Introduction :- Hii Friends..   Today I explain what is Css and why we use Css and the basic structure of css. so here I               ...
  • stored procedure with case and actions
    Intoduction :- Hii Friends... Today I  explain how to use case and action in stored procedure .  CREATE Proc [dbo].[Proc_ManageRatingA...
  • How to create pikachu character using HTML & CSS
    Hii Friends... Today I explain how to create cartoon( Pikachu character) using HTML and CSS . you can use this code in your project cop...
  • How To Make Semi-Transparent Buttons
    Intoduction :-   Hii Friends...   Today I explain how to make Semi-Transparent Buttons with the help of css. This style now a days goes t...
  • Create a Cart Popup div in HTML & CSS
    Intoduction :-   Hii Friends... Today I explain how to Create a Cart Popup div in HTML & CSS . This moduel base on mouse hover when y...
  • Awarepedia services
    Intoduction :-   Hii Friends...   Today I explain services of awarepedia.com  . Awarepedia is a online software development company and the...
  • How To scroll from bottom to top
    Intoduction :- Hii Friends...   Today I explain How To scroll from top to bottom and bottom to top, we use “scrollTop” function of jque...
  • Auto-Hiding Navbar with Javascript
    Intoduction :-   Hii Friends... today i explain how to hide a navbar when scroll the page. Fixed headers are fairly common nowadays with...

Blog Archive

  • ►  2017 (13)
    • ►  December (1)
    • ►  March (5)
    • ►  February (1)
    • ►  January (6)
  • ►  2016 (31)
    • ►  November (1)
    • ►  September (1)
    • ►  June (6)
    • ►  May (3)
    • ►  April (2)
    • ►  March (8)
    • ►  February (9)
    • ►  January (1)
  • ▼  2015 (31)
    • ►  December (3)
    • ►  November (4)
    • ►  October (18)
    • ▼  September (6)
      • How to make a hit-dot game in Asp.net using Java-S...
      • How to use Session in ASP.net
      • How to find results by click on dropdownlist selec...
      • How To Bind A Repeater In Asp.Net
      • How To Make A Responsive Grid System
      • Asp.net insert, Edit, update, delete in grid view

About Me

Unknown
View my complete profile

Copyright © Asp.net modules | Powered by Blogger
Design by Sheetal Khandelwal