Hi There,
I am trying to acheive the same sort of affect as using the if then else in
classic asp, I have a stored procedure that returns 28 columns, 8 of these
columna are the same for all results the other 20 are different depending on
the value of the @listingID parameter. The problem that I have is that I
need to have complete control over the display (see below 1), I have tried
using a datagrid but I can't seem to get it to format the display properly,
I can't have empty table cells on the page it looks ugly. I managed to get a
table control to display, but I want the columns that I decide to display in
the same format as the datagrid it self.(see the <asp:datagrid id="dgHyper"
runat="server" below).
Could someone help please, this is driving me nuts
Sean
1.
<template column>
if param <> "null" then
<table>
<tr>
<td>
Elseif formname = "Control Valves"
co9, col10,col11
some value some value
</td>
<td>
else
some value
</td>
</tr>
</table>
end if
<template column>
!----- full code snippet
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
myCommand = New SqlCommand("GetListingDetail",myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim pListingID As New SqlParameter("@listingID", SqlDbType.int)
pListingID.Value = strImageID
myCommand.Parameters.Add(pListingID)
myConnection.Open
da.SelectCommand=myCommand
ds = New DataSet()
da.Fill(ds, "tblListings")
'Dim dv as DataView = ds.Tables(0).DefaultView
Dim dc As DataColumn
For Each dc In ds.Tables(0).Columns
If Not dc.ColumnName = "ListingID" And Not dc.ColumnName =
"model" And Not dc.ColumnName = "listprice" And Not dc.ColumnName = "descri"
And Not dc.ColumnName = "manufacturer" And Not dc.ColumnName = "comments"
And Not dc.ColumnName = "formname" And Not dc.ColumnName = "username" And
Not dc.ColumnName = "lblquantity" And Not dc.ColumnName = "lbllistprice" And
Not dc.ColumnName = "lblcomments" And Not dc.ColumnName = "lbllocation"
And Not dc.ColumnName = "Location" Then
bindcolumn(dc.ColumnName, "")
End If
Next
Dim dr As DataRow
For Each dc In ds.Tables(0).Columns
Dim trow As New TableRow()
Dim tcellcolname As New TableCell()
'To Display the Column Names
For Each dr In ds.Tables(0).Rows
tcellcolname.Controls.Add(New LiteralControl(dc.ColumnName.ToString))
Next
If Not dc.ColumnName = "ListingID" And Not dc.ColumnName = "model" And
Not dc.ColumnName = "listprice" And Not dc.ColumnName = "descri" And Not
dc.ColumnName = "manufacturer" And Not dc.ColumnName = "comments" And Not
dc.ColumnName = "formname" And Not dc.ColumnName = "username" And Not
dc.ColumnName = "lblquantity" And Not dc.ColumnName = "lbllistprice" And Not
dc.ColumnName = "lblcomments" And Not dc.ColumnName = "lbllocation" And
Not dc.ColumnName = "Location" Then
trow.Cells.Add(tcellcolname)
End if
'To Display the Column Data
For Each dr In ds.Tables(0).Rows
Dim tcellcoldata As New TableCell()
If Not dc.ColumnName = "ListingID" And Not dc.ColumnName = "model" And
Not dc.ColumnName = "listprice" And Not dc.ColumnName = "descri" And Not
dc.ColumnName = "manufacturer" And Not dc.ColumnName = "comments" And Not
dc.ColumnName = "formname" And Not dc.ColumnName = "username" And Not
dc.ColumnName = "lblquantity" And Not dc.ColumnName = "lbllistprice" And Not
dc.ColumnName = "lblcomments" And Not dc.ColumnName = "lbllocation" And
Not dc.ColumnName = "Location" Then
tcellcoldata.Controls.Add(New
LiteralControl(dr(dc.ColumnName).ToString))
End if
trow.Cells.Add(tcellcoldata)
Next
If Not dc.ColumnName = "ListingID" And Not dc.ColumnName = "model" And
Not dc.ColumnName = "listprice" And Not dc.ColumnName = "descri" And Not
dc.ColumnName = "manufacturer" And Not dc.ColumnName = "comments" And Not
dc.ColumnName = "formname" And Not dc.ColumnName = "username" And Not
dc.ColumnName = "lblquantity" And Not dc.ColumnName = "lbllistprice" And Not
dc.ColumnName = "lblcomments" And Not dc.ColumnName = "lbllocation" And
Not dc.ColumnName = "Location" Then
Table1.Rows.Add(trow)
End if
Next
End Function
Sub bindcolumn(ByVal fldname As String, ByVal formatpattern As String)
Dim objbc As BoundColumn
objbc = New BoundColumn()
objbc.DataField = fldname
objbc.HeaderText = fldname
objbc.DataFormatString = formatpattern
dgHyper.Columns.Add(objbc)
dgHyper.DataSource = ds.Tables(0)
dgHyper.DataBind()
End Sub
</script>
</head>
<table cellspacing=1 cellpadding=1 width=500 border=1>
<tr>
<td valign=top>
<asp
ataGrid
ID="dg_details"
AutoGenerateColumns=False
Width="250"
HeaderStyle-BackColor="purple"
HeaderStyle-ForeColor="White"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True"
Runat=server>
<Columns>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image Width="200" Height="200" alt="Listing Image" ImageUrl='<%#
FormatURL(DataBinder.Eval(Container.DataItem, "ListingID")) %>' Runat=server
/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
</td>
<td>
<table cellspacing=1 cellpadding=1 width=250 border=1>
<tr><td valign=top>
<asp:datagrid id="dgHyper" runat="server"
HeaderStyle-BackColor="purple"
HeaderStyle-ForeColor="White"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True"
AutoGenerateColumns="False">
<COLUMNS>
<asp:TemplateColumn HeaderText="Listing Info">
<ItemTemplate>
<table border="0" width=250>
<tr>
<td align="right"><b>Manufacturer:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "manufacturer")
%></td>
</tr>
<tr>
<td align="right"><b>Model:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "model") %></td>
</tr>
<tr>
<td align="right"><b>Description:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "descri") %></td>
</tr>
</ItemTemplate>
</asp:TemplateColumn>
!--------------------------------------------------------------------------
Appear here
<asp:TemplateColumn>
<ItemTemplate>
<tr>
<td align="right"><b>Quantity:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "quantity") %></td>
</tr>
<tr>
<td align="right"><b>Price:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "listprice") %></td>
</tr>
<tr>
<td align="right"><b>Comments:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "comments") %></td>
</tr>
<tr>
<td align="right"><b>Location:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "Location") %></td>
</tr>
<tr>
<td align="right"><b>Type:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "formname") %></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</td></tr>
</table>
<asp:Table id="Table1" runat="server"
CellPadding=10
HorizontalAlign="left">
</asp:Table>
</td></tr>
</table>