Some time ago with the teacher made a. NET small project One of the pages involved with the GridView control binding data, requirements are from different data tables to detect data, binding to the GridView, I think in the front page to write judgment statement, check for a long time, finally understand, This is part of my front desk code.
<table width= "99%" height= "30px" border= "0" align= "center" cellpadding= "0" cellspacing= "0" > <tr>
<TD width= "Ten" > </td>
<td>
<%IF (flag = = "a")
{%>
<asp:gridview id= "GridView" runat= "Server" autogeneratecolumns= "False"
Gridlines= "None" showheader= "False" height= "100%" width= "100%" cssclass= "Lista" >
<rowstyle height= "25px"/>
<Columns>
<asp:templatefield headertext= "title" >
<ItemTemplate>
<table align= "left" border= "0" cellpadding= "0" cellspacing= "0" >
<tr >
<TD width= "25px" ></td>
<TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%}%>
<%IF (flag = = "B")
{%>
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "False"
Gridlines= "None" showheader= "False" height= "100%" width= "100%" cssclass= "Lista" >
<rowstyle height= "25px"/>
<Columns>
<asp:templatefield headertext= "title" >
<ItemTemplate>
<table align= "left" border= "0" cellpadding= "0" cellspacing= "0" >
<tr >
<TD width= "25px" > </td>
<TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%}%>
<%IF (flag = = "C")
{%>
<asp:gridview id= "GridView2" runat= "Server" autogeneratecolumns= "False"
Gridlines= "None" showheader= "False" height= "100%" width= "100%" cssclass= "Lista" >
<rowstyle height= "25px"/>
<Columns>
<asp:templatefield headertext= "title" >
<ItemTemplate>
<table align= "left" border= "0" cellpadding= "0" cellspacing= "0" >
<tr >
<TD width= "25px" > </td>
<TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>
</Columns>
</asp:GridView>
<%}%>
</td>
<TD width= "Ten" > </td>
</tr>
</table>
Remember: this
<%IF (flag = = "A") {%> <%}%> statement to be placed outside the GridView, otherwise there will be an error.
The values in the flag are obtained from the background.