0
我想使用GridView生成複選框字段,系統會根據totalDay的數量計算顯示多少個字段。 如果存儲在數據庫中的totalDay是7,那麼在調用eventID時會生成7個複選框,D1-D7複選框會出現;如果totalDay爲5,則會生成5個複選框,D1-D5複選框字段將會出現。如何根據數據庫中的整數值生成複選框字段?
在PHP中,我設法根據值totalDay自動生成我想要的D字段的數量。但我不知道如何在VB中編寫代碼。
的PC公平事件已持續7天,所以它會顯示用戶選擇的事件和展位後7個複選框預訂:
狂歡節2012已持續5天,因此它會顯示用戶後5個複選框選擇事件和展位預訂:
在PHP中的代碼可以生成複選框:
$query = "select * from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";
$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);
echo "<table border='0' style='width:400px;table-layout:fixed'>";
$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
if($day==0){
echo "<th>Booth</th>";
}else{
echo "<th>D".$day."</th>";
}
}
while($rows = mysql_fetch_array($result2)){
$boothAlias=$rows['boothAlias'];
$totalDay=$rows['totalDay'];
$boothID=$rows['boothID'];
echo "<tr><td>$boothAlias</td>";
for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
$d=$rows["D$day2"];
if ($d==0){
echo "<td><input name='totalDay[]' type='checkbox' value='$boothAlias $boothID $day2'/></td>";
}else{
echo "<td><input name='totalDay[]' type='checkbox' value='$boothAlias $day2' disabled='true'/></td>";
}
}
echo "</tr>";
}
echo "</table>";
}
}
我不如何調用totalD ay值並執行循環來檢查VB中的D字段。 有沒有更好的解決方案來生成複選框? 它可以重複使用只有一個項目模板來生成複選框並與D域綁定?
以下是我目前的VB代碼:
<%@ Page Language="VB" MasterPageFile="~/MasterPageMember.master" AutoEventWireup="false" CodeFile="member_view_event_list.aspx.vb" Inherits="member_view_event_list" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" runat="server"
contentplaceholderid="ContentPlaceHolder2">
<table width="80%">
<tr><td class="style10"> </td><td class="style8"> </td><td> </td></tr>
<tr><td class="style10">
<asp:Label ID="Label1" runat="server" Text="Select Event:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlEventList" runat="server"
DataSourceID="SqlDataSourceEvent" DataTextField="eventTitle"
DataValueField="eventID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceEvent" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT DISTINCT [eventTitle], [eventID] FROM [booth_eventinfo]">
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
<asp:Label ID="Label2" runat="server" Text="Select Booth:"></asp:Label>
</td><td class="style8">
<asp:DropDownList ID="ddlBoothList" runat="server"
DataSourceID="SqlDataSourceBooth" DataTextField="boothAlias"
DataValueField="boothID" AutoPostBack="True" Width="200">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceBooth" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [boothAlias], [boothID] FROM [booth_eventinfo] WHERE ([eventID] = @eventID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEventList" Name="eventID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td><td>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
</td><td>
</td></tr>
<tr><td class="style9" colspan="3">
<asp:GridView ID="GridViewDay" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSourceDay" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Day1" SortExpression="D1" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("D1") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Day2" SortExpression="D2" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("D2") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Day3" SortExpression="D3" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server" Checked='<%# Bind("D3") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Day4" SortExpression="D4" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox4" runat="server" Checked='<%# Bind("D4") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Day5" SortExpression="D5" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox5" runat="server" Checked='<%# Bind("D5") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Day6" SortExpression="D6" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBox6" runat="server" Checked='<%# Bind("D6") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceDay" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [D1], [D7], [D6], [D5], [D4], [D3], [D2] FROM [booth_eventinfo] WHERE ([boothID] = @boothID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlBoothList" Name="boothID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr><td class="style10">
</td><td class="style8">
</td><td>
</td></tr>
我想你想使用'Repeater'而不是'GridView'。但是,它看起來像你的SQL查詢總是返回7天。從哪裏可以確定這種動態的天數? –