Solved

Dropdown List index changed ASp.net,c#

Posted on 2008-10-31
25
8,085 Views
Last Modified: 2013-12-17
if i  , change the dropdown list  , i want the correspondin  price value in gridview column .
Plz help...

I want price value to change accordingly to selection on restaurant name of dropdown list.


<Columns>

                <asp:BoundField DataField="fid" HeaderText="fid" />

                <asp:BoundField HeaderText="Fname" DataField="fname"/>

                <asp:TemplateField HeaderText="rname">

                    <ItemTemplate>

                        <asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

                        </asp:DropDownList>

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:BoundField HeaderText="price"  />

                <asp:TemplateField HeaderText="Quantity">

                    <EditItemTemplate>

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                    </EditItemTemplate>

                    <ItemTemplate>

                        <asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />

            </Columns>
 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        string restaurantname = DropDownList1.SelectedValue.ToString();

        SqlCommand price = new SqlCommand("select price from maintable where rid='" + restaurantname + "'", con);

        SqlDataAdapter value_price = new SqlDataAdapter(price);

        DataSet ds1 = new DataSet();

        value_price.Fill(ds1, "Table");

        // I need to show the price according to selection of dropdown list

        //

        

   }

Open in new window

0
Comment
Question by:Rajar Ahmed
  • 13
  • 11
25 Comments
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22850407
Ok I am back, as your reference to the last question. How is the price binded at the first place?

Let say you have several restaurant link to that main table, I guess there will be multiple row there for different rid. Was that the price you binded took the first row value as the first time you bind the grid ?

JINN
0
 
LVL 3

Expert Comment

by:biodooms
ID: 22850486
I would recommend you to put the dropdownlist into the edittemplate. Then do an findcontrol on update and modify the value in the database
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22850575
so far i dint binded any price in gridviw..

As u no v binded fid,restaurant name...

Exactly , I ve a price column in table which is float .

Price differs from selection of restaurant in dropdownlist .

Nope Its right now empty column . i got to bind from the scratch for price column .

I puzzled how to use gridview cell of price to bind by using dropdown list  selectedindex .i havent bind for the first  row of price.. ...

Plz tell me how to load first value and correspondin value . when user changes dropdownlist indexx....

Thankxx in advance.....


0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22851035
Meeran,

Last time I did something like this it was quite tricky, so you might take awhile to figure out. I dont know which one is the best option, because normally they will have a dropdownList in the edittemplate, show it when edit and save it.

You want to have a dropdown on view, select, raise event and change gridView data. This:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) will be called after the GridView is bind.

This is what my idea was (look at the code)

You might wanna try around first to get to the right cell, but this should be your direction

JINN




protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        DropDownList currentDDL = (DropDownList)sender;

        string restaurantname = currentDDL .SelectedValue.ToString();

        SqlCommand price = new SqlCommand("select price from maintable where rid='" + restaurantname + "'", con);

        SqlDataAdapter value_price = new SqlDataAdapter(price);

        DataSet ds1 = new DataSet();

        value_price.Fill(ds1, "Table");

      

        //you might wanna playaround until you find the appropriated cell

         TableCell cell =  currentDDL.Parent As TableCell;

	 cell.Text =  ds1.Tables[0].Rows[0][0];        

   }

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22851566

this line -->>>tableCell cell =  currentDDL.Parent As TableCell;
error : ; expected





Error was here..

tableCell cell =  currentDDL.Parent As TableCell;// I think it is for vb 

        

          cell.Text =  ds1.Tables[0].Rows[0][0];  

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22851673
TableCell cell = (TableCell)currentDDL.Parent;//AFtr i made a change
       
          cell.Text =  ds1.Tables[0].Rows[0][0];  

this was the errr

Error    4    Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)



0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22855849
This code is not populating price from db , price column is empty .
but not no errors .

I need to dispay the first row wit apt price and also if i change index of drop , i need to display appropriate price for that , restaurants ...

Plz help..

 protected void Page_Load(object sender, EventArgs e)

    {

  if (!IsPostBack)

	{

	       

		 //query and populate ddlName

	        string constr = ConfigurationManager.AppSettings["constring"];

	        SqlConnection myconnection = new SqlConnection(constr);

	        DataSet ds = new DataSet();

            myconnection.Open();

	        SqlDataAdapter da = new SqlDataAdapter("Select distinct fid,(Select fname from foodtable where fid = maintable.fid)as fname from maintable", myconnection);

	        da.Fill(ds);		

		    GridView1.DataSource = ds.Tables[0];

		    GridView1.DataBind();

		    myconnection.Close();

        }
 

    }

    
 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if(e.Row.RowType == DataControlRowType.DataRow)

        {

            //get the ID

            string fid = e.Row.Cells[0].Text;

           //find the current dropdown list:

            DropDownList ddlName = (DropDownList)e.Row.FindControl("dropdownlist1");

           //NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist

            PopulateDropDownListNameByID(fid, ddlName);

        }

    }

        private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)

    {

        //query and populate ddlName

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter("SELECT fid, resname FROM maintable INNER JOIN resttable ON resttable.rid = maintable.rid WHERE maintable.fid = " + fid, myconnection);

        da.Fill(ds);

        ddlname.Items.Clear();

        ddlname.DataSource = ds.Tables[0];

        ddlname.DataValueField = "resname";

        ddlname.DataTextField = "resname";

        ddlname.DataBind();

    }
 
 
 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {
 

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DropDownList currentDDL = (DropDownList)sender;

        string restaurantname = currentDDL.SelectedValue.ToString();

        SqlCommand price = new SqlCommand("select price from maintable where rid='" + restaurantname + "'", myconnection);

        SqlDataAdapter value_price = new SqlDataAdapter(price);

        DataSet ds1 = new DataSet();

        value_price.Fill(ds1, "Table");

        TableCell cell = (TableCell)currentDDL.Parent;

        cell.Text = (string)ds1.Tables[0].Rows[0][1];        

    

    }
 
 
 

My aspx page....
 
 

<Columns>

                <asp:BoundField DataField="fid" HeaderText="fid" />

                <asp:BoundField HeaderText="Fname" DataField="fname"/>

                <asp:TemplateField HeaderText="rname">

                    <ItemTemplate>

                    <asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" >

                        </asp:DropDownList>

                    </ItemTemplate>

                     </asp:TemplateField>

                <asp:BoundField HeaderText="price"  />

                <asp:TemplateField HeaderText="Quantity">

                    <EditItemTemplate>

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                    </EditItemTemplate>

                    <ItemTemplate>

                        <asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />

            </Columns>

        </asp:GridView>

        &nbsp;&nbsp;

   

Open in new window

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22870910
Hi,

It was a busy weekend for me? I am just back now? How is your question, have you got it working?

Try my code, and the above one that I suggested

JINN

PS: As I mentioned once, you better use INNER JOIN instead of what you are doing now, when you have much more product, this will increase your performance.


   

 protected void Page_Load(object sender, EventArgs e)

    {

  if (!IsPostBack)

        {

               

                 //query and populate ddlName

                string constr = ConfigurationManager.AppSettings["constring"];

                SqlConnection myconnection = new SqlConnection(constr);

                DataSet ds = new DataSet();

            myconnection.Open();

                SqlDataAdapter da = new SqlDataAdapter("SELECT price, maintable.fid, fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid", myconnection);

                da.Fill(ds);            

                    GridView1.DataSource = ds.Tables[0];

                    GridView1.DataBind();

                    myconnection.Close();

        }

 

    }

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22873463
My problems..

1.No, its not working . Am still getting the empty price column .when datafield is not set to price in aspx page.


2Aftr settings
When i used this above code am getting multiple fid coulumns with populated values in price columns ...
i mean to say ,
pizza
pizza
burger
burger...

Several times

cud u just check my query is r8 in dropdownlist index selected index ...


3. I , still used with this improper way of result , i changed dropdown list to select other restaurant

i got this error,
Syntax error converting the varchar value 'Restaurant A' to a column of data type int







 protected void Page_Load(object sender, EventArgs e)

    {

  if (!IsPostBack)

	{

	       

		 //query and populate ddlName

            //string constr = ConfigurationManager.AppSettings["constring"];

            //SqlConnection myconnection = new SqlConnection(constr);

            //DataSet ds = new DataSet();

            //myconnection.Open();

            //SqlDataAdapter da = new SqlDataAdapter("Select distinct fid,(Select fname from foodtable where fid = maintable.fid)as fname from maintable", myconnection);

            //da.Fill(ds);		

            //GridView1.DataSource = ds.Tables[0];

            //GridView1.DataBind();

            //myconnection.Close();

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        myconnection.Open();

        SqlDataAdapter da = new SqlDataAdapter("SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid", myconnection);

        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();

            }
 

    }

    
 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if(e.Row.RowType == DataControlRowType.DataRow)

        {

            //get the ID

            string fid = e.Row.Cells[0].Text;

           //find the current dropdown list:

            DropDownList ddlName = (DropDownList)e.Row.FindControl("dropdownlist1");

           //NOW you have the current ID and the dropdownlist -> populate the dllName dropdownlist

            PopulateDropDownListNameByID(fid, ddlName);

        }

    }

        private void PopulateDropDownListNameByID(string fid, DropDownList ddlname)

    {

        //query and populate ddlName

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter("SELECT fid, resname FROM maintable INNER JOIN resttable ON resttable.rid = maintable.rid WHERE maintable.fid = " + fid, myconnection);

        da.Fill(ds);

        ddlname.Items.Clear();

        ddlname.DataSource = ds.Tables[0];

        ddlname.DataValueField = "resname";

        ddlname.DataTextField = "resname";

        ddlname.DataBind();

    }
 
 
 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

       string constr = ConfigurationManager.AppSettings["constring"];

       SqlConnection myconnection = new SqlConnection(constr);

       DropDownList currentDDL = (DropDownList)sender;

       string restaurantname = currentDDL.SelectedValue.ToString();

       SqlCommand price = new SqlCommand("select price from maintable where rid='" + restaurantname + "'", myconnection);

       SqlDataAdapter value_price = new SqlDataAdapter(price);

       DataSet ds1 = new DataSet();

       value_price.Fill(ds1, "Table");

       TableCell cell = (TableCell)currentDDL.Parent;

       cell.Text =(string)ds1.Tables[0].Rows[0][1];          

    }

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22873476
 
ERROR LINE :
DataSet ds1 = new DataSet();

i got this error,
Syntax error converting the varchar value 'Restaurant A' to a column of data type int

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874354
First can you run this query in your Database SQL enterprise?

SELECT price, maintable.fid,  fname FROM maintable
INNER JOIN foodtable ON maintable.fid = foodtable.fid
GROUP BY price, maintable.fid, fname

If you see prices in that query, then the binding is wrong. I gotta know how is the table look like, I guess there will be several rows with different price but the same fid, or fname. In that case, you would still see thing like:

price  fid   fname
5         4    pizza
6         4    pizza

In that's case you have to exclude the price from the query and populate it up on the restaurant. (like we did in the last question), it's will be tough, but it can do.

JINN

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874379
My suggestion is: dont compact everything in this grid, take out the restaurant name. and the grid will display the details food price of that restaurant.

The dropdownlist (out of gridview) has several value:
For example you select Jinn rest:
price  fid   fname
10       2    pizza
7         3    berger

Then you select Mac rest
price  fid   fname
 9         2    pizza
 8         3    berger

You can have another tab to select on food and this time
Select fid= 2 (pizza)
price  Resname
 10         jinn rest
9           Mac rest

This way it's easier for you to maintain your application, test and debug.

JINN

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22874556
s . i see a price column in db query anlyser . ....with repetitive fid values.......

but i got stuck in webappln .. with the error..
1.SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid GROUP BY price, maintable.fid, fname'" + restaurantname + "'", myconnection
Incorrect syntax near 'Restaurant C'.




Ur suggestion is good ,
but the thing; . i should move accordingly to company design ....





0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874675
Trust me in this. Convince your boss, tell him, the idea you are dealing with now is not very user friendly and hard to maintain .

Let say you have way too much dropdown list with the same data (restaurant names) in 1 gridView. Let say if you have 20 foods, then the desired GridView will have 20 rows. And 20 dropdownlists contain exactly the same data. And let say you have 10 restaurant, then you would have: 20 ddl with 10 exact items.

Beside, the task to populate such layout also take huge brains >.<. when you have more records, page will slow because of the dynamic populate...

User will also confuse when they have made several selection, cause they see prices from several  restaurant and not so sure if they mean for same food (especially for those have bad eyes)

JINN
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874689
SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid
GROUP BY price, maintable.fid, fname'" + restaurantname + "'"

What's that restaurantname at the end? The Group By is mostly the same as the select one except aggregate data like COUNT , SUM, AVG...

if you want to have the condition where Res name = then you should do:

SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid
WHERE restaurantname = 'jinn rest'
 GROUP BY price, maintable.fid, fname

Play with the string to get appropriate result

JINN


0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22874742

okay ...... so ders no possibilty of loading price values according to my design ..and also not user friendly ...
Then i ll say ...wat should be done .. Thanks .....


hmm well, am now changin my design .. n am workin out witth ur query ...soon ll tell u ..wats happening in my design .....

Thanks again ....
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22874870
now creating a new design .....as u said ......

I loaded dropdown list by sqldatasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>"
            SelectCommand="SELECT [rid], [resname] FROM [resttable]"></asp:SqlDataSource>


On my page , it displays ....

1. Dropdownlist with restaurants.
2.Gridview
fname,price,quantity,addtocart


i still now c a empty price column .  where am i wrong .. ??

My revised code here....

Lukin for further assistance.....

Thankss....





<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"

            DataTextField="resname" AutoPostBack="True" DataValueField="rid" Style="left: 52px; position: relative;

            top: 86px">

        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>"

            SelectCommand="SELECT [rid], [resname] FROM [resttable]"></asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server" Style="left: 45px; position: relative;

            top: 122px" AutoGenerateColumns="False">
 
 
 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
 

public partial class newgrid : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

     if (!IsPostBack)

	{

	       

		 //query and populate ddlName

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        myconnection.Open();

        SqlDataAdapter da = new SqlDataAdapter("Select distinct fid,(Select fname from foodtable where fid = maintable.fid)as fname from maintable", myconnection);

        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();

   

            }

    }
 
 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DropDownList currentDDL = (DropDownList)sender;

        string restaurantname = currentDDL.SelectedValue.ToString();

        SqlCommand price = new SqlCommand("SELECT  maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid GROUP BY  maintable.fid, fname'" + restaurantname + "'", myconnection);

        SqlDataAdapter value_price = new SqlDataAdapter(price);

        DataSet ds1 = new DataSet();

        value_price.Fill(ds1, "Table");

        TableCell cell = (TableCell)currentDDL.Parent;

        cell.Text = (string)ds1.Tables[0].Rows[0][1];
 
 

    }

    }
 
 
 

            <Columns>

                <asp:BoundField DataField="fname" HeaderText="foodname" />

                <asp:BoundField HeaderText="Price" />

                <asp:TemplateField HeaderText="Quantity">

                    <EditItemTemplate>

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                    </EditItemTemplate>

                    <ItemTemplate>

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

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:ButtonField HeaderText="Buy" Text="AddtoCart" />

            </Columns>

        </asp:GridView>

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22874879

If the preicous code is confusing, now i pasted correctly ....
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"

            DataTextField="resname" AutoPostBack="True" DataValueField="rid" Style="left: 52px; position: relative;

            top: 86px">

        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>"

            SelectCommand="SELECT [rid], [resname] FROM [resttable]"></asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server" Style="left: 45px; position: relative;

            top: 122px" AutoGenerateColumns="False">

            <Columns>

                <asp:BoundField DataField="fname" HeaderText="foodname" />

                <asp:BoundField HeaderText="Price" />

                <asp:TemplateField HeaderText="Quantity">

                    <EditItemTemplate>

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

                    </EditItemTemplate>

                    <ItemTemplate>

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

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:ButtonField HeaderText="Buy" Text="AddtoCart" />

            </Columns>

        </asp:GridView>
 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
 

public partial class newgrid : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

     if (!IsPostBack)

	{

	       

		 //query and populate ddlName

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        myconnection.Open();

        SqlDataAdapter da = new SqlDataAdapter("Select distinct fid,(Select fname from foodtable where fid = maintable.fid)as fname from maintable", myconnection);

        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();

   

            }

    }
 
 

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DropDownList currentDDL = (DropDownList)sender;

        string restaurantname = currentDDL.SelectedValue.ToString();

        SqlCommand price = new SqlCommand("SELECT  maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid GROUP BY  maintable.fid, fname'" + restaurantname + "'", myconnection);

        SqlDataAdapter value_price = new SqlDataAdapter(price);

        DataSet ds1 = new DataSet();

        value_price.Fill(ds1, "Table");

        TableCell cell = (TableCell)currentDDL.Parent;

        cell.Text = (string)ds1.Tables[0].Rows[0][1];
 
 

    }

    }

Open in new window

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874899
Glad to hear, well it is possible but it would lead you to have couple of nightmares at night.

As you are redesigning your pages. Let start with, view food details upon restaurant, this page (or Tab) you have an DropDownList (outside of GridView) which listed all restaurant name.

And a GridView which is binded upon this dropdownlist selection. You have to be clear what is the link,a dn what is the key of the restable ???

Your ddlName has event selectedIndexChange where you rebind your gridview upon this query:

check the column and field but this should be the idea.

(you might wanna take alook at using objectdatasource for this gridView if you want.

JINN






string restname = ddlname.SelectedValue
 

String query = "SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid WHERE resname =  '" + restname  + "' GROUP BY price, maintable.fid, fname "
 

SqlDataAdapter da = new SqlDataAdapter(query, myconnection);

        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();

Open in new window

0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22874935
When you do it in a new way, you dont have to make it as this complicated, try the following code.

And now as I understand you have a rid is the key and foreign key I guess, use rid as the value

JINN



 protected void Page_Load(object sender, EventArgs e)

    {

     if (!IsPostBack)	       

		 //query and populate ddlName

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

        DataSet ds = new DataSet();

        myconnection.Open();

        SqlDataAdapter da = new SqlDataAdapter("SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid GROUP BY price, maintable.fid, fname ", myconnection);        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();

   

            }

    }
 
 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        string constr = ConfigurationManager.AppSettings["constring"];

        SqlConnection myconnection = new SqlConnection(constr);

	myconnection.Open();

        string rid = DropDownList1.SelectedValue;

	String query = "SELECT price, maintable.fid,  fname FROM maintable INNER JOIN foodtable ON maintable.fid = foodtable.fid WHERE rid =  '" + rid  + "' GROUP BY price, maintable.fid, fname "

    

	SqlDataAdapter da = new SqlDataAdapter(query, myconnection);

        da.Fill(ds, "Table");

        GridView1.DataSource = ds.Tables[0];

        GridView1.DataBind();

        myconnection.Close();	

    }

Open in new window

0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22875110
well , toooo good ur , made it so, simple...........................

well , the thing s my mind is always unidirectional din think othrway ...THankss yaar..

I ve one more thing in this gridview,, to get complete my issue , can i ask here itself or in a new question .....???
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 500 total points
ID: 22875136
It's up to you ^^. I am glad you work it out or at least have a better design and understanding. ^^

You can accept my answer and post a new one. ^^ of course I would like it. Because the new one might come with new issue and can be expanded. And I think the mod would like to see that. When future reference needed, it will be easier to specify

JINN
0
 
LVL 18

Author Closing Comment

by:Rajar Ahmed
ID: 31512040
Helps a lot . Overview was very good .
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22875243
:D you are welcome ^^ Glad to helps

JINN

PS: (Very minor point)  It would be easier for future reference if you accept the previous solution right before the one you accepted ^^
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 22875299
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now