The GridView control write judgment statement in C # __c#

Source: Internet
Author: User

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>
&LT;TD width= "Ten" >&nbsp;</td>
<td>


&LT;%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 >

&LT;TD width= "25px" ></td>
&LT;TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>

</Columns>
</asp:GridView>
<%}%>




&LT;%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 >

&LT;TD width= "25px" > </td>
&LT;TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>

</Columns>
</asp:GridView>

<%}%>


&LT;%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 >

&LT;TD width= "25px" > </td>
&LT;TD width= "450px" align= "left" >
Other content
</td>
</tr>
</table>
</ItemTemplate>
<itemstyle cssclass= "lista" height= "25px" horizontalalign= "left"/>
</asp:TemplateField>

</Columns>
</asp:GridView>

<%}%>

</td>
&LT;TD width= "Ten" >&nbsp;</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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.