2012-05-08 6 views
0

VBコーディングに関する知識は限られています。私は現在、お客様が希望する展示イベントとブース番号を選択し、次に借りたい日を予約するシステムを作成しています。GridViewを使用してデータベースの各フィールドのチェックボックスを生成する方法

デフォルトでは、GridViewコントロールではチェックボックスフィールドを追加できますが、1行のデータに対して1つのチェックボックスしか生成されません。

タイトルの状態として、データベース呼び出しD1、D2、D3、D4、D5、D6、D7の各フィールドのチェックボックスをどのように生成するのか分かりません。デフォルト値はそれぞれ0です。 ここでは、すべての単一フィールドに、チェックした値を取得し、対応するD1-D7フィールドに盗まれるチェックされた値を取得するチェックボックスがあるようにしたい場合、チェックされた値は値0を1に更新します。

次に、チェックした値をデータベースに保存するようにコーディングすべきですか? default.aspxまたはdefault.aspx.vb?

gridviewを使用する代わりに、チェックボックスを生成するよう提案されていますか?

私が欲しいもの

enter image description here

のGridView

を使用して、デフォルトのビューを

enter image description here

私のコーディング:

あなたがあなたの 'BoundField' を変更する必要が
<%@ 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"> 



    <style type="text/css"> 
     .style8 
     { 
      width: 46px; 
     } 
     .style9 
     { 
     } 
     .style10 
     { 
      width: 86px; 
     } 
    </style> 



    </asp:Content> 

<asp:Content ID="ContentPlaceHolder2" runat="server" 
    contentplaceholderid="ContentPlaceHolder2"> 



    <table width="80%"> 
     <tr><td class="style10">&nbsp;</td><td class="style8">&nbsp;</td><td>&nbsp;</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> 
       &nbsp;</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"> 
      &nbsp;</td><td class="style8"> 
       &nbsp;</td><td> 
       &nbsp;</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:BoundField DataField="D1" HeaderText="Day1" SortExpression="D1" /> 
        <asp:BoundField DataField="D2" HeaderText="Day2" SortExpression="D2" /> 
        <asp:BoundField DataField="D3" HeaderText="Day3" SortExpression="D3" /> 
        <asp:BoundField DataField="D4" HeaderText="Day4" SortExpression="D4" /> 
        <asp:BoundField DataField="D5" HeaderText="Day5" SortExpression="D5" /> 
        <asp:BoundField DataField="D6" HeaderText="Day6" SortExpression="D6" /> 
        <asp:BoundField DataField="D7" HeaderText="Day7" SortExpression="D7" /> 
       </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"> 
      &nbsp;</td><td class="style8"> 
       <asp:CheckBox ID="CheckBox1" runat="server" /> 
      </td><td> 
       &nbsp;</td></tr> 


</table> 

</asp:Content> 
+0

タイトルに「ASP .NET VB - 」などのプレフィックスを付けないでください。それがタグのためのものです。 –

答えて

0

'TemplateField' forあなたが望む各CheckBoxコントロール。以下のコード例は、これを行う方法を示しています。 DataField値のバインディング式の構文に注意してください。

<asp:TemplateField HeaderText="Day1" SortExpression="D1" HeaderStyle-HorizontalAlign="Center"> 
    <ItemTemplate> 
    <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("D1") %>' /> 
    </ItemTemplate> 
</asp:TemplateField> 
0

これはあなたを助けるかもしれません。グリッドビューを使用する代わりに、asp:CheckBoxListを使用できます。これは、7日間のチェックボックスのみを配置する必要がある場合です。リストが作成されたら、イメージに示されている外観に従うように、CSSを使用して水平方向にスタイルを設定できます。このlinkは、チェックボックスリストのプレビューを表示します。

質問の2番目の部分については、最終送信時にdefault.aspx.vbに保存することができます。

グリッドビューを使用する場合は、7つのテンプレート列を追加し、それをデータソースにバインドする必要があります。

関連する問題