0

Possible Duplicate:
Conditional Logic in ASP.net page

I am new to ASP.NET.

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.

<form name="form1" runat="server" class="FormDetail">
<table width="80%" align="center" >
    <tr>
        <td width="20%"></td>
        <td width="80%" class="PageTitle"></td>
        <td width="20%">
            <asp:Button runat="server" CommandName="AddNewProposal" ID="AddNewProposal" Text="Create Note" 
            href="ProposalCreateNote.aspx?ProposalID=ProposalID=" 
            title="Create Note" class="button3"/>           
        </td>
    </tr>
</table>   

    <div style="width:40%; margin-right: auto; margin-left: auto;">
        <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"
            >

        <Fields>
            <asp:TemplateField HeaderText="ProposedID" SortExpression="Name" > 
                <ItemTemplate >
                    <asp:Label ID="ProposalID" runat="Server" style="text-align:left;" 
                     Text='<%# Eval("ProposedID")%>' />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="MDFName" HeaderText="MDF Name" SortExpression="MDFName" />  

                <asp:TemplateField HeaderText="VendorName">
                    <ItemTemplate>
                        <asp:Label ID="lblVendorName" runat="Server" style="text-align:left;" Text='<%# Eval("VendorName")%>'/>
                    </ItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList id="insertVendorName" datasourceid="VendorSqlDataSource"
                            datatextfield="VendorName" DataValueField="VendorID" 
                            SelectedValue='<%# Bind("VendorID") %>'
                            OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged" 
                            runat="server" AutoPostBack="true">
                            <asp:ListItem Text="Select" Value="-1"></asp:ListItem>  
                        </asp:DropDownList>

                        <asp:SqlDataSource ID="VendorSqlDataSource"  ConnectionString="<%$Connectionstrings:ConnectionString%>"
                            SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"  runat="server">
                        </asp:SqlDataSource>
                    </InsertItemTemplate>

                    <EditItemTemplate>
                        <asp:DropDownList id="updateVendorName" datasourceid="VendorSqlDataSource"  AutoPostBack="true"
                        datatextfield="VendorName"  DataValueField="VendorID"  
                        SelectedValue='<%# Bind("VendorID") %>'     
                        runat="server" 
                        OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged"  />                       
                        <asp:SqlDataSource ID="VendorSqlDataSource"  ConnectionString="<%$Connectionstrings:ConnectionString%>"
                            SelectCommand="SELECT VendorID, VendorName from MDF_Vendor"  runat="server">
                        </asp:SqlDataSource>
                    </EditItemTemplate>
                </asp:TemplateField>

        </Fields>

        </asp:DetailsView>                   
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ConnectionStrings:ConnectionString %>"
            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"
        >   
            <SelectParameters>
                    <asp:QueryStringParameter Name="ProposedID" QueryStringField="ProposedID"  runat="server" />
            </SelectParameters>                        
            <UpdateParameters> 
            <asp:Parameter Name="ProposedID" Type="Int32" />
            </UpdateParameters>                    
        </asp:SqlDataSource>
    </div>

<hr align="center" width="96%" size="1" color="darkblue" /> 

<!-- //////////////////// NEED TO HIDE THI TABLE WHERE QueryString Mode=Insert ///////////////////// -->
<table  align="center"  width="96%" id="table2" border="0">
    <tr>
         <td class="center TitleSmall">Notes</td>
     </tr>
    <tr>
        <td width="48%">
    <asp:GridView ID="GridView_Note" runat="server"
    AutoGenerateColumns="False" 
        DataKeyNames="ProposedNoteID"
        DataSourceID="dsProposalNote" 


        ShowFooter="true"
        CssClass="mGrid"
        PagerStyle-CssClass="pgr"
        AlternatingRowStyle-CssClass="alt"                      
    >
    <AlternatingRowStyle ForeColor="Black"  BackColor="#F7F6F3"  VerticalAlign="top" />
    <HeaderStyle BackColor="#B5DAFF" Font-Bold="True" HorizontalAlign="center" />
    <PagerStyle BackColor="Gold" ForeColor="White" HorizontalAlign="Center" />    
    <FooterStyle Font-Bold="True" ForeColor="White"  BackColor="" />
        <Columns>

            <asp:BoundField DataField="ProposedNoteID" HeaderText="ID"  ItemStyle-Width="5%" />
            <asp:TemplateField ItemStyle-Width="70%">
                <ItemTemplate>

                    <asp:Label runat="server" DataField="Note" HeaderText="Note" Text='<%#Eval("Note") %>' />

                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CreatedBy" HeaderText="Created By"  ItemStyle-Width="13%"/>
            <asp:BoundField DataField="CreatedDate" HeaderText="Created Date"  ItemStyle-Width="12%" DataFormatString="{0:dd/MM/yyyy}"/>

            <asp:TemplateField HeaderText="Delete"> 
                <ItemTemplate> 

                    <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" 

                  OnClientClick="return confirm('Are you certain you want to delete this?');"/> 

                </ItemTemplate> 
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
        <asp:sqldatasource ID="dsProposalNote" runat="server"  ConnectionString="<%$ConnectionStrings:ConnectionString %>"
        SelectCommand="Select * from MDF_ProposedNote where ProposedID = @ProposedID"    
        DeleteCommand="DELETE MDF_ProposedNote where ProposedNoteID = @ProposedNoteID"
            >
        <SelectParameters>
            <asp:QueryStringParameter Name="ProposedID" QueryStringField="ProposedID"  runat="server" />
        </SelectParameters>

    </asp:sqldatasource>

    </td>
        <td></td>
        <td width="48%"></td>
    </tr>
</table>
</form>

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.

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.

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.

2
  • Can you show us the code related to the GridView? Commented Oct 17, 2012 at 16:04
  • Hi @Abe, as requested, I have updated the code related to GridView... Thanks for helping. Commented Oct 17, 2012 at 17:28

1 Answer 1

0

You could wrap the table in an asp:placeholder or asp:panel and then in your Page_Load event query the QueryString collection for your "mode" key value pair and hide or show accordingly.

HTML

<asp:Panel id="pnlNotes" runat="server">
   ... Table and gridView
</asp:Panel>

Code Behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
         if (Request.QueryString["mode"] != null && Request.QueryString["mode"] == "Insert")
         {
             pnlNotes.Visible = false;
         }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.