Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I got a combobox that I bind to database and when I select a order from combobox
it must display OrderDetails and Customer Dfetails on seperate gridviews i achieved that now i want to have an "All" option in that combobox when ALL is selected it display all ordersDetails and Customer Details from database.Note I got tables which are ordersDetails and Customer Details they have foreign key from Orders table.I retrieve data using a foreign key but now option ALL doesnt have foreign key thats the problem that i am facing

My code for select combobox binding

SQL
SELECT [ID],
[orderName] ,
from
Orders


my gridview select code that display selected item on gridview according to what is selected from combobox

SQL
SELECT CustomerName,CustomerName,

FROM Orders inner join OrderDetails on Orders .ID = OrderDetails .orderRef
WHERE ID = @.orderRef
Posted
Comments
AmitDutta_Bokaro 15-Jun-12 7:22am    
have u inserted the all text in combobox
kolisa 15-Jun-12 7:24am    
My problem i dont know if must i insert on combobox properties or on sql db Table

For all statement don't need to Where Condition
It will show all data.
No need to foreign key.

Like as...

SELECT CustomerName,CustomerName,
FROM Orders inner join OrderDetails on Orders .ID = OrderDetails.orderRef

Try...........
 
Share this answer
 
Comments
kolisa 15-Jun-12 7:35am    
My problem how do i bind those gridviews to ALL option becouse is in the same combobox with other option that have WHERE Clause
Upniwesh 15-Jun-12 7:45am    
Are you use ComboboxColumn in your grid view or display normal in data table???
kolisa 15-Jun-12 7:50am    
I use grid view to display only, i just have a combobox that i select from on top of the page
Upniwesh 15-Jun-12 7:58am    
Retrieve the DataTable from your sql with
"SELECT CustomerName,CustomerName,
FROM Orders inner join OrderDetails on Orders .ID = OrderDetails.orderRef"

and store in dt.

dt is the DataTable Object

and write in cs file
gridview1.DataSource = dt;
gridview1.DataBind();

I hope your problem will solve......
kolisa 15-Jun-12 9:03am    
remember i should have to select, how to i put or becouse in the second select i dont want a WHERE condtion
hi you can try this ,

XML
<asp:GridView ID="grd" runat="server" CaptionAlign="Top" Width="100%" SelectedIndex="0" CellPadding="4"
                   AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
                              GridLines="Vertical" ForeColor="Black">
                  <Columns>

                      <asp:TemplateField HeaderText="Select Record">
                          <ItemTemplate>
                           put controls here like:
  <asp:label id="lblLabel" runat="server" text="<%# Bind("tableColumn") %>" xmlns:asp="#unknown"></asp:label>
                              </ItemTemplate>
                      </asp:TemplateField>
</Columns>

Apply join query on both tables assign the result into some dataTable which is having result of all data.
assign it to grd.DataSource and call grd.DataBind();

this will be the one way where you can bind the columns of query result to the gridview...
Or you can retreive join result and simply use following logic.

some DataTable object=result of your join query; //or you can use dataAdapter and Dataset also
grd.DataSource=some table;
grd.DataBind()
 
Share this answer
 
Comments
kolisa 15-Jun-12 9:05am    
I got 2 select statement one with WHERE Condition and other one is without condition. how do i put them together
preet88 16-Jun-12 4:52am    
why you want 2 different select statement when you want to display whole data of orders and the details of customer related to that orders.
I suppose i may be getting your question wrongly.. Will you come again with little more explanation about what you want to do???
kolisa 18-Jun-12 4:28am    
I got a gridview when ever i select combobox the gridview changes meaning it diplays data which is relevent to what has been selected which is fine i manage to do that but now i want to have all in that combobox and when ever all is select it on combobox the gridview display everything that is in database(as that combobox got fields on it so ALL option should diplay that data on a gridview that links in all those fileds binded in combobox),i dont know if that functionality is possible
preet88 18-Jun-12 4:42am    
see it is possible to diplay whatever is there in your join queries

in your comboBox_SelectedIndexChanged event write like this

comboBox1_SelectedIndexChanged(object sender, EventArgs e){

if(combobox1.SelectedValue=="All") {

/* write your appropriate query here for fetching all the data(apply joins if you are having multiple tables)*/

}}I hope this will help :)
kolisa 26-Jul-12 8:13am    
Thanks

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