2.0: DropDownList with GridView

R

R.A.M.

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,
[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/
 
R

rgiltner

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. said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top