Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
DataSource controls really do work in ASP.NET Whidbey - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

DataSource controls really do work in ASP.NET Whidbey

I wrote some code in ASP.NET Whidbey last night to use the DataSource controls.  Wow, this stuff really does work.  I used it to perform some queries against my Web Search with .NET code.  Here it is and it actually does work.  There is a drop down list box that is populated with the server name.  On a change of the server name drop down, the grid on the page changes and displays all of the items that are found in the database that are associated with that domain name.  The one question that I have had is how would you put a blank item into the drop down list box as the selected item and keep the query from running the first time thru?  I assume it is something in the Page_Load event.  Suggestions?

Wally

<%@ Page Language="C#" MasterPageFile="~/ExampleMasterPage.master" Title="Data Source Controls"%>

<asp:Content ID="cExample" ContentPlaceHolderID="cph1" Runat="server"><asp:DropDownList

ID="ddlDomainName" Runat="server" DataSourceID="sqldsDDL" DataTextField="DomainName"

DataValueField="DomainName" AutoPostBack="True">

</asp:DropDownList>

<asp:SqlDataSource ID="sqldsResults" Runat="server" SelectCommand="SELECT [SearchUrl] FROM [tblSearchResults] WHERE ([DomainName] = @DomainName)"

ConnectionString="<%$ ConnectionStrings:sqlResultsConnection %>">

<SelectParameters>

<asp:ControlParameter Name="DomainName" Type="String" ControlID="ddlDomainName" PropertyName="SelectedValue"></asp:ControlParameter>

</SelectParameters>

</asp:SqlDataSource>

<asp:SqlDataSource ID="sqldsDDL" Runat="server" SelectCommand="SELECT DISTINCT DomainName FROM dbo.tblSearchResults"

ConnectionString="<%$ ConnectionStrings:DDLLookupString %>">

</asp:SqlDataSource>

<asp:DataList ID="dlResults" Runat="server" DataSourceID="sqldsResults">

<ItemTemplate>

SearchUrl:

<asp:Label Text='<%# Eval("SearchUrl") %>' Runat="server" ID="SearchUrlLabel">

</asp:Label><br />

<br />

</ItemTemplate>

</asp:DataList>

</asp:Content>

Comments

Phil Winstanley said:

Yup, that is indeed cool.

Now we have to fight even harder to get newbies to ASP.NET to put their data access code in seperate classes, perferably not in the same project as the Web Application!

Grrrrr.....
# July 6, 2004 5:48 PM

Dave Sussman said:

Adding blank items: set the AppendDataBoundItems property of the listbox/dropdown to True. This means that when binding the existing items aren't cleared. Add the static blank item by just placing an asp:ListItem within the list tags.
# July 7, 2004 6:09 AM

Wallym said:

Thank you Dave.

Wally
# July 7, 2004 7:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)