Here is a solution:
sqlstr = "SELECT ids, name, ISNULL(width,300) as width, height, description FROM pictures ";
SqlDataAdapter MyAdapter = new SqlDataAdapter();
MyAdapter.SelectCommand = new SqlCommand(sqlstr, conPubs);
Look at the first line:
I am telling SQL to replace any null value in width with 300. That's because I intent to give every picture a width value, but not a height value. Browsers will automatically give a value to the height according to the picture's dimensions, so all I need is a width.
The rest looks like jargon but works. Take a look at the line that begins with
<%# ((Convert.IsDBNull ... I am telling ASP.NET to give the picture a height value only if the value in the database is not null. I could've done this in the SQL instruction, but I decided to do it inside the Datalist.
<asp: DataList id="datalist1" border=0 RepeatDirection="Horizontal" RepeatColumns="3" runat="server">
<ItemTemplate>
<img src="http://www.webmaster-talk.com/images/<%# DataBinder.Eval(Container.DataItem,"name")%>"
width = "<%#DataBinder.Eval(Container.DataItem, "width")%>"
<%# ((Convert.IsDBNull(DataBinder.Eval(Container.DataI tem, "height"))) ? "" : "height = " + DataBinder.Eval(Container.DataItem, "height")) %>
alt="<%# DataBinder.Eval(Container.DataItem,"description")% >" />
</ItemTemplate>
</asp: DataList>
It works, but the script looks complicated. I wonder if there's an easier way to do it.
__________________________________________________ ___________
http://www.carbotek.org