473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

2.0: DropDownList with GridView

Hello,
Could you help me please to define GridView associated to
DropDownList...
My DropDownList "Publishers" should show publishers' names
from SQL Server table Publishers. My GridView "BooksOnDotNET"should
show books published by selected publisher. (Tables' definition
below.)
Here is part of .aspx:

<asp:DropDownList ID="Publishers" runat="server"
DataSourceID="PublishersSQL" DataTextField="Name"
DataValueField="Name">
</asp:DropDownList>
<asp:SqlDataSource ID="PublishersSQL" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLServerConnectionString %>"
SelectCommand="SELECT Name FROM Publishers ORDER BY
Name">
</asp:SqlDataSource>
<asp:GridView ID="BooksOnDotNET" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="BooksSQL"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775"
/>
</asp:GridView>
<asp:SqlDataSource ID="BooksSQL" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLServerConnectionString %>"
SelectCommand="SELECT Books.Tytuł, Books.Autor,
Books.ISBN FROM Booksi INNER JOIN Publications ON Booksi.ISBN =
Publications.ISBN WHERE (Publications.PublisherName = @Publisher)
ORDER BY
Books.Title" >
<SelectParameters>
<asp:ControlParameter ControlID="Publishers"
Name="Publisher" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

Here you have definitions of Publishers, Books, Publications (SQL
Server 2005):

CREATE TABLE [dbo].[Publishers](
[Name] [varchar](50) NOT NULL,
[Address] [varchar](75) NULL,
[WWWPage] [varchar](50) NULL,
[email] [varchar](50) NULL,
[Phone] [varchar](15) COLLATE NULL,
CONSTRAINT [PK_Publishers] PRIMARY KEY CLUSTERED
(
[Name] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Books](
[ISBN] [nchar](13) NOT NULL,
[Title] [varchar](50) NOT NULL,
[Autor] [varchar](50) NULL,
[OriginalTitle] [varchar](50) NULL,
[PublicationsNumber] [smallint] NULL,
CONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED
(
[ISBN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Publications](
[ISBN] [nchar](13) NOT NULL,
[PublicationName] [varchar](50) NOT
NULL,
[Number] [varchar](10) NOT NULL,
[City] [varchar](30) NULL,
[Year] [smallint] NULL,
[Translation] [varchar](50) NULL,
CONSTRAINT [PK_Publications] PRIMARY KEY CLUSTERED
(
[ISBN] ASC,
[PublisherName] ASC,
[Number] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Here is part of Web.Config:

<connectionStrings>
<add
name="SQLServerConnectionString"
connectionString="Data Source=PC\SQLEXPRESS;Initial
Catalog=DemoDotNET;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>

PROBLEM: There's sotmething wrong because GridView is not displayed (I
had it visible for the moment but data displayed was incorrect.)
Please help to define asp: controls.

Thank you very much!
/RAM/
Jun 8 '06 #1
1 1211
First off, make sure the query returns results when you run it in Query
Analyzer or some such. Second, I have had problems letting gridview
(and detailsview) generate columns dynamically. Sometimes they won't
show anything, so Go in, and Edit the fields in the Gridview and tell
it which fields I want to display.

Hope that helps.

Tex

R.A.M. wrote:
Hello,
Could you help me please to define GridView associated to
DropDownList...
My DropDownList "Publishers" should show publishers' names
from SQL Server table Publishers. My GridView "BooksOnDotNET"should
show books published by selected publisher. (Tables' definition
below.)
Here is part of .aspx:

<snip>

Jun 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
0
by: dawg1998 | last post by:
I am able to populate a DropDownList control within multiple rows of a GridView with the following code: `````````````````````````````````````````````````````` <asp:GridView id="gvGridView"...
0
by: Ben | last post by:
Hi, It's about a database containing (for simplifying) three fields: 'placenr' (primary key), 'place' and 'color'. The records are updatable (Edit/Update button) in a gridview. For updating the...
7
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another...
0
by: sgtmarcjones | last post by:
How do I access a dropdownlist that is nested within a Formview ItemTemplate Gridview Template? I want to see a label (lgbTimeKeep ! TextValue of ddlName dropdownlist) instead of a dropdownlist...
3
by: Brian VanDyke | last post by:
I have to display a table with customer data (GridView). However, I want to be able to show DropDownList controls inside one of the columns, not just textbox controls. Is this possible? Is it...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
0
by: Fabrizio | last post by:
Hi all. I have a field in a gridview as templatefield which is a label in view mode and a dropdownlist in edit mode with his datasource. This gridview is inserted as templatefield in another...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.