Wednesday, April 16, 2008

Prototyping in ASP.Net - asp:SqlDataSource Example

Recently, I've been doing a bunch of ASP.Net. One of ASP.Net's best features is its ability to be used for realistic rapid prototyping.

Here is a simple example that executes a SQL query and displays the results.

In the aspx... (be sure and notice the "$" in the connection string)

<asp:sqldatasource id="SqlDSCoreCoverages" runat="server" connectionstring="<%$ ConnectionStrings:ConnectionString_DEV %>" >"
             select coverage_description, display_order
             from prod_cov
        whereid = :argProductVersionId
             order by display_order

<table cellpadding="3" style="border: 1px #333333 solid;">
                   <asp:gridview id="GridView1" runat="server" datasourceid="SqlDSCoreCoverages" autogeneratecolumns="False" gridlines="None">
                      <headerstyle cssclass="SectionHeader">
                         <asp:BoundField DataField="coverage_description"  HeaderText="Included Core Coverages"
                            ReadOnly="True" SortExpression="coverage_description" />

In the aspx.cs [codebehind] ...

this.SqlDSCoreCoverages.SelectParameters.Add("argProductVersionId", productVersionId.ToString());



rajesh said...

hey ur example helped a lott tanks.. hey how to check whether the retreived value fom database is empty using these statements can u help me out...

Jason said...

It's been a while since I looked at this code.

I think you can do something like...

protected void SqlDSCoreCoverages_Selected(object sender, SqlDataSourceStatusEventArgs e)
if (e.AffectedRows == 0)
Response.Write("There are no records available");

Anonymous said...

Excelente informacion, lo que andaba buscando :):):):):):)