Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a dropdown list like this

XML
<asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True">
        <asp:ListItem>Select</asp:ListItem>
        <asp:ListItem>TRAVELONG</asp:ListItem>
        <asp:ListItem>ONETRAVEL</asp:ListItem>
    </asp:DropDownList>


and a grid view with sqlconnection:

XML
<asp:GridView ID="GridView1" runat="server"    CellPadding="4" ForeColor="#333333"
        GridLines="None" onrowcommand="GridView1_RowCommand"
        AutoGenerateColumns="False">
        <Columns>
       <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" />
    </Columns>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:BartConnectionString %>"
        SelectCommand="SELECT select * [Test]">
        </asp:SqlDataSource>


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
Updated 27-Mar-13 21:55pm
v2

1 solution

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");
  Con.Open();
  Da = new SqlDataAdapter(" select * from yourtable where ColumnName =	'"+DropDownList1.SelectedItem.Text+"' ",Com); 
  Da.Fill(Ds);
  GridView1.DataSource=Ds;
  GridView1.DataBind();

  Con.Close();


 }

}
 
Share this answer
 
Comments
amitesh1989 28-Mar-13 6:06am    
i get this error Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
[no name] 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'.
[no name] 28-Mar-13 8:40am    
please make sure that column name of your sql table is same as 'TRAVELONG'

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