Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Gridview Tables , +
I have a dropdown list like this
 
<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:
 
<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 27-Mar-13 22:53pm
Edited 27-Mar-13 22:55pm
v2

1 solution

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

 }
 
}
  Permalink  
Comments
amitesh1989 at 28-Mar-13 6:06am
   
i get this error Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.
Susheel Kumar Verma at 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 at 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 at 28-Mar-13 6:49am
   
cause when i use this i got this error Invalid column name 'TRAVELONG'.
Susheel Kumar Verma at 28-Mar-13 8:40am
   
please make sure that column name of your sql table is same as 'TRAVELONG'
Susheel Kumar Verma at 28-Mar-13 8:39am
   
no need to use boundfield.
amitesh1989 at 28-Mar-13 8:57am
   
thanks i made some changes and it work thanks for your reply
Susheel Kumar Verma at 28-Mar-13 12:09pm
   
welcome.

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

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
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