<form id="form1" runat="server">
Country: <asp:DropDownList ID="ddlCountry" AutoPostBack="true" runat="server">
<asp:ListItem Text="All" Value="" />
<asp:ListItem Text="Argentina" Value="Argentina" />
<asp:ListItem Text="Belgium" Value="Belgium" />
<asp:ListItem Text="Brazil" Value="Brazil" />
<asp:ListItem Text="Canada" Value="Canada" />
<asp:ListItem Text="Denmark" Value="Denmark" />
<asp:ListItem Text="Finland" Value="Finland" />
<asp:ListItem Text="France" Value="France" />
<asp:ListItem Text="Germany" Value="Germany" />
</asp:DropDownList><br />
<asp:DataList ID="dlCustomers" runat="server" RepeatLayout="Table" RepeatColumns="3"
CellPadding="2" CellSpacing="2">
<ItemTemplate>
<table cellpadding="2" cellspacing="0" border="1" style="width: 200px; height: 100px;
border: dashed 2px #04AFEF; background-color: #B0E2F5">
<tr>
<td>
<b><u><span class="name">
<%# Eval("ContactName") %></span></u></b>
</td>
</tr>
<tr>
<td>
<b>City: </b><span class="city">
<%# Eval("City") %></span><br />
<b>Postal Code: </b><span class="postal">
<%# Eval("PostalCode") %></span><br />
<b>Country: </b><span class="country">
<%# Eval("Country")%></span><br />
<b>Phone: </b><span class="phone">
<%# Eval("Phone")%></span><br />
<b>Fax: </b><span class="fax">
<%# Eval("Fax")%></span><br />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</form>
protected void Page_Load(object sender, EventArgs e)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT top 10 * FROM Customers where Country=@Country or @Country=''";
SqlCommand cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue("@Country", ddlCountry.SelectedItem.Value);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
dlCustomers.DataSource = ds;
dlCustomers.DataBind();
}
}
}
}