title: ASP.NET - If condition inline with HTML code
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/368169/conditional-logic-in-asp-net-page">Conditional Logic in ASP.net page</a>  </p>
  </blockquote>
  
  
  
  <p>I am new to ASP.NET.</p>
  
  <p>Lets say I have couple tables, and some tables I used TD tag to place the GridView and DetailsView in side.  Note that these DetailsView and GridView are not related like one click another refresh, just display records.  In DetailsView, I also have Add, Edit, and Delete Option.  Example below.</p>
  
  <pre><code>&lt;form name="form1" runat="server" class="FormDetail"&gt;
  &lt;table width="80%" align="center" &gt;
      &lt;tr&gt;
          &lt;td width="20%"&gt;&lt;/td&gt;
          &lt;td width="80%" class="PageTitle"&gt;&lt;/td&gt;
          &lt;td width="20%"&gt;
              &lt;asp:Button runat="server" CommandName="AddNewProposal" ID="AddNewProposal" Text="Create Note" 
              href="ProposalCreateNote.aspx?ProposalID=ProposalID=" 
              title="Create Note" class="button3"/&gt;           
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;   
  
      &lt;div style="width:40%; margin-right: auto; margin-left: auto;"&gt;
          &lt;asp:DetailsView AutoGenerateRows="False" DataKeyNames="ProposedID" DataSourceID="SqlDataSource2"
              HeaderText="Proposal Detail View" ID="DetailsView1" 
              runat="server" Width="100%" validateRequest="false" 
              CssClass="products"
              HeaderStyle-CssClass="header"
              FieldHeaderStyle-CssClass="fieldHeader"
              AlternatingRowStyle-CssClass="alternating"
              RowStyle
              CommandRowStyle-CssClass="command"
              PagerStyle-CssClass="pager"
              &gt;
  
          &lt;Fields&gt;
              &lt;asp:TemplateField HeaderText="ProposedID" SortExpression="Name" &gt; 
                  &lt;ItemTemplate &gt;
                      &lt;asp:Label ID="ProposalID" runat="Server" style="text-align:left;" 
                       Text='&lt;%# Eval("ProposedID")%&gt;' /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
              &lt;asp:BoundField DataField="MDFName" HeaderText="MDF Name" SortExpression="MDFName" /&gt;  
  
                  &lt;asp:TemplateField HeaderText="VendorName"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblVendorName" runat="Server" style="text-align:left;" Text='&lt;%# Eval("VendorName")%&gt;'/&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;InsertItemTemplate&gt;
                          &lt;asp:DropDownList id="insertVendorName" datasourceid="VendorSqlDataSource"
                              datatextfield="VendorName" DataValueField="VendorID" 
                              SelectedValue='&lt;%# Bind("VendorID") %&gt;'
                              OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged" 
                              runat="server" AutoPostBack="true"&gt;
                              &lt;asp:ListItem Text="Select" Value="-1"&gt;&lt;/asp:ListItem&gt;  
                          &lt;/asp:DropDownList&gt;
  
                          &lt;asp:SqlDataSource ID="VendorSqlDataSource"  ConnectionString="&lt;%$Connectionstrings:ConnectionString%&gt;"
                              SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"  runat="server"&gt;
                          &lt;/asp:SqlDataSource&gt;
                      &lt;/InsertItemTemplate&gt;
  
                      &lt;EditItemTemplate&gt;
                          &lt;asp:DropDownList id="updateVendorName" datasourceid="VendorSqlDataSource"  AutoPostBack="true"
                          datatextfield="VendorName"  DataValueField="VendorID"  
                          SelectedValue='&lt;%# Bind("VendorID") %&gt;'     
                          runat="server" 
                          OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged"  /&gt;                       
                          &lt;asp:SqlDataSource ID="VendorSqlDataSource"  ConnectionString="&lt;%$Connectionstrings:ConnectionString%&gt;"
                              SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"  runat="server"&gt;
                          &lt;/asp:SqlDataSource&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
          &lt;/Fields&gt;
  
          &lt;/asp:DetailsView&gt;                   
          &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ConnectionStrings:ConnectionString %&gt;"
              SelectCommand="SELECT p.*
                          , (SELECT VendorName FROM MDF_Vendor WHERE VendorID = p.VendorID) AS VendorName
                          , (SELECT VendorBUName FROM MDF_VendorBU WHERE VendorBUID = p.VendorBUID) AS VendorBUName
                          FROM dbo.MDF_Proposed p Where p.ProposedID = @ProposedID"
              UpdateCommand="UPDATE [MDF_Proposed] SET [VendorID] = @VendorID
                          , [VendorBUID] = @VendorBUID
                          , [MDFSummary] = @MDFSummary
                          , [MDFAmount] = @MDFAmount
                          , [BeginDate] = @BeginDate
                          , [EndDate] = @EndDate
                          WHERE ProposedID = @ProposedID"
              InsertCommand = "INSERT INTO [MDF_Proposed] ([VendorID], [VendorBUID], [MDFName], [BeginDate], [EndDate], [CreatedBy]) 
                               VALUES (@VendorID, @VendorBUID, @MDFName, @BeginDate, @EndDate, '1234') "
              DeleteCommand = "DELETE  [MDF_Proposed]  WHERE ProposedID = @ProposedID"
          &gt;   
              &lt;SelectParameters&gt;
                      &lt;asp:QueryStringParameter Name="ProposedID" QueryStringField="ProposedID"  runat="server" /&gt;
              &lt;/SelectParameters&gt;                        
              &lt;UpdateParameters&gt; 
              &lt;asp:Parameter Name="ProposedID" Type="Int32" /&gt;
              &lt;/UpdateParameters&gt;                    
          &lt;/asp:SqlDataSource&gt;
      &lt;/div&gt;
  
  &lt;hr align="center" width="96%" size="1" color="darkblue" /&gt; 
  
  &lt;!-- //////////////////// NEED TO HIDE THI TABLE WHERE QueryString Mode=Insert ///////////////////// --&gt;
  &lt;table  align="center"  width="96%" id="table2" border="0"&gt;
      &lt;tr&gt;
           &lt;td class="center TitleSmall"&gt;Notes&lt;/td&gt;
       &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td width="48%"&gt;
      &lt;asp:GridView ID="GridView_Note" runat="server"
      AutoGenerateColumns="False" 
          DataKeyNames="ProposedNoteID"
          DataSourceID="dsProposalNote" 
  
  
          ShowFooter="true"
          CssClass="mGrid"
          PagerStyle-CssClass="pgr"
          AlternatingRowStyle-CssClass="alt"                      
      &gt;
      &lt;AlternatingRowStyle ForeColor="Black"  BackColor="#F7F6F3"  VerticalAlign="top" /&gt;
      &lt;HeaderStyle BackColor="#B5DAFF" Font-Bold="True" HorizontalAlign="center" /&gt;
      &lt;PagerStyle BackColor="Gold" ForeColor="White" HorizontalAlign="Center" /&gt;    
      &lt;FooterStyle Font-Bold="True" ForeColor="White"  BackColor="" /&gt;
          &lt;Columns&gt;
  
              &lt;asp:BoundField DataField="ProposedNoteID" HeaderText="ID"  ItemStyle-Width="5%" /&gt;
              &lt;asp:TemplateField ItemStyle-Width="70%"&gt;
                  &lt;ItemTemplate&gt;
  
                      &lt;asp:Label runat="server" DataField="Note" HeaderText="Note" Text='&lt;%#Eval("Note") %&gt;' /&gt;
  
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:BoundField DataField="CreatedBy" HeaderText="Created By"  ItemStyle-Width="13%"/&gt;
              &lt;asp:BoundField DataField="CreatedDate" HeaderText="Created Date"  ItemStyle-Width="12%" DataFormatString="{0:dd/MM/yyyy}"/&gt;
  
              &lt;asp:TemplateField HeaderText="Delete"&gt; 
                  &lt;ItemTemplate&gt; 
  
                      &lt;asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" 
  
                    OnClientClick="return confirm('Are you certain you want to delete this?');"/&gt; 
  
                  &lt;/ItemTemplate&gt; 
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
          &lt;asp:sqldatasource ID="dsProposalNote" runat="server"  ConnectionString="&lt;%$ConnectionStrings:ConnectionString %&gt;"
          SelectCommand="Select * from MDF_ProposedNote where ProposedID = @ProposedID"    
          DeleteCommand="DELETE MDF_ProposedNote where ProposedNoteID = @ProposedNoteID"
              &gt;
          &lt;SelectParameters&gt;
              &lt;asp:QueryStringParameter Name="ProposedID" QueryStringField="ProposedID"  runat="server" /&gt;
          &lt;/SelectParameters&gt;
  
      &lt;/asp:sqldatasource&gt;
  
      &lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td width="48%"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What I would like to do is that, if the QueryString is sending with insert mode on the URL (Page1.aspx?mode=insert). On page load, I want the DetailsView1 to be in the Insert mode, and hide the Table2, which contains the GridView (GridView_Note) and other HTMLcodes.</p>
  
  <p>If this is classic ASP, I believe that I can store the queryString value in a variable and do and IF statement before the  to display based on the condition of Page.asp?mode=insert.</p>
  
  <p>Any suggestions how to accomplish this in ASP.NET? How can I store a variable and inject it inline with HTML codes?  Please let me know if I confused you.  Thanks in advance.</p>