可能重复:
ASP.net 页面中的条件逻辑
我是 ASP.NET 的新手。
假设我有几个表,有些表我使用 TD 标签将 GridView 和 DetailsView 放在一边。注意这些DetailsView和GridView是没有关系的,就像一键刷新一样,只是显示记录而已。在 DetailsView 中,我还有添加、编辑和删除选项。下面的例子。
<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>
我想做的是,如果 QueryString 在 URL 上以插入模式发送(Page1.aspx?mode=insert)。在页面加载时,我希望 DetailsView1 处于插入模式,并隐藏 Table2,其中包含 GridView (GridView_Note) 和其他 HTMLcode。
如果这是经典的 ASP,我相信我可以将 queryString 值存储在一个变量中,然后根据 Page.asp?mode=insert 的条件显示之前的 do 和 IF 语句。
任何建议如何在 ASP.NET 中完成此任务?如何存储变量并将其与 HTML 代码内联?如果我让你感到困惑,请告诉我。提前致谢。