我一直在处理一个 HTML 页面,该页面在第二页上显示来自 SQL 数据库的表,该表按第一页上的单选按钮排序。我的首选语言是 C#,我似乎无法正确构建第二页。目前我正在尝试将 IF 语句与 LINQ 结合使用,但它不起作用。谁能告诉我如何进行?顺便说一句,我是一个完全的业余爱好者。
HTML 代码:
<body>
<h1>Server Request Form</h1>
<form id="sortradio" action="searchresults.aspx" method="get">
<fieldset>
<legend>Sort Order</legend>
<input type="radio" id="titledesc" name="sortorder" value="Title Desc" />
<label for="titledesc">By Title - Descending</label>
<input type="radio" id="titleasc" name="sortorder" value="Title" />
<label for="titleasc">By Title - Ascending</label>
<input type="radio" id="iddesc" name="sortorder" value="Id Desc" />
<label for="iddesc">By ID - Descending</label>
<input type="radio" id="idasc" name="sortorder" value="Id" />
<label for="idasc">By ID - Ascending</label>
<input type="submit" value="Get Info" />
</fieldset>
</form>
</body>
ASP 代码:
<h1>You are sorting by <% Response.Write(Request.QueryString("sortorder"))%>.</h1>
<%
Dim SortingOrder = Request.QueryString("sortorder")
%>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Summary" HeaderText="Summary" SortExpression="Summary" />
<asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
<asp:BoundField DataField="GenreId" HeaderText="GenreId" SortExpression="GenreId" />
<asp:CheckBoxField DataField="Authorized" HeaderText="Authorized" SortExpression="Authorized" />
<asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime" SortExpression="CreateDateTime" />
<asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime" SortExpression="UpdateDateTime" />
</Columns>
</asp:GridView>
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:Database1.MDFConnectionString1 %>" providername="<%$ ConnectionStrings:Database1.MDFConnectionString1.ProviderName %>" selectcommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [Authorized], [CreateDateTime], [UpdateDateTime] FROM [Review] ORDER BY @sortorder">
<Selectparameters>
<asp:querystringparameter name="sortorder" querystringfield="sortorder" />
</Selectparameters>
</asp:SqlDataSource>
</form>`