Click here to Skip to main content
13,090,178 members (49,380 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
I have a dropdown list like this

<asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True">

and a grid view with sqlconnection:

<asp:GridView ID="GridView1" runat="server"    CellPadding="4" ForeColor="#333333"
        GridLines="None" onrowcommand="GridView1_RowCommand"
       <asp:BoundField DataField="Portal" HeaderText="Portal" />
        <asp:BoundField DataField="TID" HeaderText="TID" />
        <asp:BoundField DataField="PNR" HeaderText="PNR" />
        <asp:BoundField DataField="TicketNumber" HeaderText="Ticket Number" />
        <asp:BoundField DataField="ESACCode" HeaderText="ESACCode" />
        <asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" />
        <asp:BoundField DataField="Remarks" HeaderText="Remarks" />
        <asp:BoundField DataField="UnusedTicketAmount" HeaderText="UnusedTicketAmount" />
        <asp:BoundField DataField="ddlUnusedAmount" HeaderText="ddlUnusedAmount" />
        <asp:BoundField DataField="AirlinePenality" HeaderText="AirlinePenality" />
        <asp:BoundField DataField="ddlAirlinePenality" HeaderText="ddlAirlinePenality" />
        <asp:BoundField DataField="NetRefundProcess" HeaderText="NetRefundProcess" />
        <asp:BoundField DataField="ddlNetRefundProcess" HeaderText="ddlNetRefundProcess" />
        <asp:BoundField DataField="RefundableCommission" HeaderText="RefundableCommission" />
        <asp:BoundField DataField="ddlRefundableCommission" HeaderText="ddlRefundableCommission" />
        <asp:BoundField DataField="CouponRefunded" HeaderText="CouponRefunded" />
        <asp:BoundField DataField="RefundType" HeaderText="RefundType" />
 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:BartConnectionString %>"
        SelectCommand="SELECT select * [Test]">

Now if i have more than one value of Travelong in my database and when i select Travelong from my dropdown list and press search button all the data show in the gridview can any one tell me how to do that. how can i do that thanks in advance
Posted 27-Mar-13 21:53pm
Updated 27-Mar-13 21:55pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can do this by adding code on button click in yourpage.aspx.cs
here is a sample code

protected void BtnSerch_Click(object sender, EventArgs e)
 DataSet Ds = new DataSet();
 SqlDataAdapter Da = new SqlDataAdapter();
 SqlConnection Con;
 if (DropDownList1.SelectedIndex !=0)
  Con = new SqlConnection(" your Connextion String");
  Da = new SqlDataAdapter(" select * from yourtable where ColumnName =	'"+DropDownList1.SelectedItem.Text+"' ",Com); 

amitesh1989 28-Mar-13 6:06am
i get this error Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
Susheel Kumar Verma 28-Mar-13 6:28am
if you are using code behind then you have to remove

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BartConnectionString %>"
SelectCommand="SELECT select * [Test]">

from your .aspx page
amitesh1989 28-Mar-13 6:48am
if i am not using sqlconnection than i guess i have to bind boundfield with gridview field am i rite !!!???
amitesh1989 28-Mar-13 6:49am
cause when i use this i got this error Invalid column name 'TRAVELONG'.
Susheel Kumar Verma 28-Mar-13 8:39am
no need to use boundfield.
Susheel Kumar Verma 28-Mar-13 8:40am
please make sure that column name of your sql table is same as 'TRAVELONG'
amitesh1989 28-Mar-13 8:57am
thanks i made some changes and it work thanks for your reply
Susheel Kumar Verma 28-Mar-13 12:09pm

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100