<%@ Page Title="" Language="C#" MasterPageFile="Step.Master" AutoEventWireup="true" CodeBehind="step2.aspx.cs" Inherits="Survery.admin.step2" MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 
 

 <table width="90%">
 <tr>
 <td  valign="top"  style=" width:200px; height:1000px; color:#ffffff; background-image:url(images/wrap_bg.jpg)">


<div class="side_bar">
		 
				 <ul>
				<li >使用说明</li>
				<li>定义标题</li>
				<li class="currentitem">定义选项</li>
				 
			</ul>
 
 </td>

<td valign="top">

<div style=" margin-left:50px; margin-top:50px;">
 
<b>Step3. 设定问表单每一个选项名称和选项内容</b>
 
  
<div style=" padding:20px;">
 
 
     
        
        <table  class="table">
        <tr>
        <th width="150px">
           （1）问题名称：
            
            
        </th>
            <td>

<asp:TextBox ID="subjectTextBox"  ValidationGroup="inserts" Width="400" runat="server" Text='<%# Bind("subject") %>' />
            <asp:RequiredFieldValidator   ValidationGroup="inserts" ControlToValidate="subjectTextBox" runat="server" ID="RequiredFieldValidator1" ErrorMessage="*" Display="Dynamic"></asp:RequiredFieldValidator>
      
            </td>
        </tr>


        <tr>
          <th>
          （2）问题类型：
         </th>
            <td>
          
          <asp:RadioButtonList Width="500" RepeatColumns="2" RepeatDirection="Horizontal"
               ClientIDMode="Static" id="itemtype" runat="server">
                     <asp:ListItem Text="下拉框" Value="DropDownList"></asp:ListItem>
                    <asp:ListItem Text="单选框" Value="RadioButtonList"></asp:ListItem> 
                    <asp:ListItem Text="复选框" Value="CheckBoxList"></asp:ListItem>
                    <asp:ListItem Text="单行文本框" Value="TextBox"></asp:ListItem>
                    <asp:ListItem Text="多行文本框" Value="MultiTextBox"></asp:ListItem>
                    <asp:ListItem Text="标签" Value="Label"></asp:ListItem>
                    <asp:ListItem Text="日期" Value="Date"></asp:ListItem>
                    <asp:ListItem Text="附件" Value="FileUpload"></asp:ListItem>
                    <asp:ListItem Text="分组选项" Value="GroupOption"></asp:ListItem>

                   
            </asp:RadioButtonList>  

            <div id="div_gpblock" style="display:none">
            
            数字范围<asp:DropDownList runat="server" ID="coin" Width=100px>
            <asp:ListItem Text="3" Value="3"></asp:ListItem>
            <asp:ListItem Text="4" Value="4"></asp:ListItem>
            <asp:ListItem Text="5" Selected="True" Value="5"></asp:ListItem>
            <asp:ListItem Text="6" Value="6"></asp:ListItem>
            <asp:ListItem Text="7" Value="7"></asp:ListItem>
            <asp:ListItem Text="8" Value="8"></asp:ListItem>
            <asp:ListItem Text="9" Value="9"></asp:ListItem>
            </asp:DropDownList>
            <br />
            范围文本(由低至高)<br />
           <asp:TextBox runat="server" ID="bad"  Text="差"  class="gptext"></asp:TextBox>
            <asp:TextBox runat="server" ID="mid"  Text="中" class="gptext"></asp:TextBox>
            <asp:TextBox runat="server" ID="good"  Text="好" class="gptext"></asp:TextBox> 

            </div>



            <div id="div_optioncount" style="display:none">
            
               每行选项的个数： 
            <asp:TextBox ID="txt_col"    Text="3" runat="server"></asp:TextBox>  

            </div>

            
             
          </td>
         </tr>
       

          


        <tr>
        
        <th>
       （3）不能不空：
            </th>
            <td>
             <asp:CheckBox runat="server" ID="cb_mustfilled" />
        
      </td>
        </tr>
       
       
        <tr>
        <th>
             （4）单独一行：
        </th>
        <td>
        <div class="td_singlerow">
       <asp:CheckBox runat="server" ID="cb_issinglerow" ClientIDMode="Static" /> 
        </div>
        </td>


        </tr>

            <tr>
                <th>

                </th>
                <td>

    <asp:Button ID="InsertButton" runat="server" ValidationGroup="inserts" CausesValidation="True" 
                Text="添加"  CssClass="btn btn-primary" onclick="InsertButton_Click"  />
            &nbsp;<asp:Button ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="取消" CssClass="btn btn-default" 
                onclick="InsertCancelButton_Click"  />
                </td>
            </tr>
        
        </table>
         
 
 <p></p>






     

注意:如果修改了ID，则ID号必须唯一且小于30，修改ID号的大小可以更改问题的显示顺序
<asp:Literal runat="server" ID="lt_preview"></asp:Literal>

<br />
    <asp:GridView ID="GridView1"    CssClass="table "  runat="server" AutoGenerateColumns="False" 
        DataKeyNames="autoid" DataSourceID="SqlDataSource1"  
         GridLines="None"
        onrowdatabound="GridView1_RowDataBound"  
       >
        <Columns>
           
           
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"   ItemStyle-Width="80px"  />
          
            <asp:BoundField DataField="id" HeaderText="ID"    ItemStyle-Width="50px" />
           
            <asp:BoundField DataField="subject" HeaderText="投票问题名称"    ItemStyle-Width="300px" />
             
           <asp:TemplateField  ItemStyle-Width="100px">
              <HeaderTemplate>
                <div style=" margin:8px;">问题类型</div>
              </HeaderTemplate>
           <ItemTemplate>
             <asp:Label runat="server" ID="names"  Text='<%#Bind("typesname")%>' ></asp:Label>
           </ItemTemplate>
           
           
           <EditItemTemplate>
            <asp:DropDownList Width="95"   SelectedValue='<%# Bind("types") %>'   id="itemtype" runat="server">
                    <asp:ListItem Text="下拉框" Value="DropDownList"></asp:ListItem>
                    <asp:ListItem Text="单选框" Value="RadioButtonList"></asp:ListItem> 
                    <asp:ListItem Text="复选框" Value="CheckBoxList"></asp:ListItem>
                    <asp:ListItem Text="单行文本框" Value="TextBox"></asp:ListItem>
                    <asp:ListItem Text="多行文本框" Value="MultiTextBox"></asp:ListItem>
                    <asp:ListItem Text="标签" Value="Label"></asp:ListItem> 
                    <asp:ListItem Text="日期" Value="Date"></asp:ListItem>
                     <asp:ListItem Text="附件" Value="FileUpload"></asp:ListItem>
                         <asp:ListItem Text="分组选项" Value="GroupOption"></asp:ListItem>
            </asp:DropDownList> 
           
           </EditItemTemplate>
           
             </asp:TemplateField>
       
       
         <asp:TemplateField  ItemStyle-Width="60px">
              <HeaderTemplate>
              是否必填
              </HeaderTemplate>
           <ItemTemplate>
                <%#Eval("mustfilled").ToString()=="1"?"是":"否" %>
           </ItemTemplate>
           
           
           <EditItemTemplate>
            <asp:CheckBox runat="server" ID="cb2_mustfilled"   />
           </EditItemTemplate>
         </asp:TemplateField>






            <asp:TemplateField  ItemStyle-Width="60px">
              <HeaderTemplate>
                单独一行
              </HeaderTemplate>
           <ItemTemplate>
               <%#Eval("issinglerow").ToString()=="1"?"是":"否" %>
           </ItemTemplate>
           
            <EditItemTemplate>
              <asp:CheckBox runat="server" ID="cb2_issinglerow"   />
           </EditItemTemplate>
           </asp:TemplateField>





          <asp:BoundField DataField="col" HeaderText="每行列数"  ItemStyle-Width="60px"/>
          
           <asp:TemplateField ItemStyle-Width="120px" >
           <ItemTemplate>
               <asp:Label ID="popup" runat="server" Text=""></asp:Label>
               
                <asp:Label ID="types" runat="server" Text=<%#Eval("types") %> Visible="false" ></asp:Label>
                <asp:Label ID="activeid" runat="server" Text=<%#Eval("activeid") %> Visible="false" ></asp:Label>
                 <asp:Label ID="id" runat="server" Text=<%#Eval("id") %> Visible="false" ></asp:Label>
                 
           </ItemTemplate>
           </asp:TemplateField>
       
      
        </Columns>
        <RowStyle  HorizontalAlign=Left Width=130px Height="30px"/>
    </asp:GridView>
    
    
    
    
    <asp:Panel runat="server" ID="pnl_next">
    
 
</asp:Panel>
    
    
    
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"    
     OldValuesParameterFormatString="old_{0}"  ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    
        DeleteCommand="DELETE FROM [Survery_subjects] WHERE [autoid] = @old_autoid; delete from survery_options where id=@old_id and activeid=@activeid " 
         
        SelectCommand="SELECT * FROM [survery_subjects] where activeid=@activeid    " 
        
        UpdateCommand=" 
        if(@id>30)
         return

        if(not exists( select * from Survery_subjects where id=@id and  activeid=@activeid)) 
        begin
             update [Survery_subjects] SET col=@col, [subject] = @subject, typesname=@typesname,  
             [types] = @types, [id] = @id,
             mustfilled=@mustfilled , issinglerow=@issinglerow WHERE [autoid] = @old_autoid
             end
         else
         begin

          update [Survery_subjects] SET col=@col, [subject] = @subject, typesname=@typesname,  
        [types] = @types,  
         mustfilled=@mustfilled , issinglerow=@issinglerow WHERE [autoid] = @old_autoid 
         end
         
         update survery_options set id=@id where id=@old_id and activeid=@activeid 
          " 
        
        onupdating="SqlDataSource1_Updating"
         >
        
        <DeleteParameters>
           <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </DeleteParameters>
        
         <SelectParameters>
          <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </SelectParameters>
       
       
        <UpdateParameters>
            <asp:Parameter Name="subject" Type="String" />
            <asp:Parameter Name="types" Type="String" />
             <asp:Parameter Name="typesname" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="old_autoid" Type="Int32" />
            <asp:Parameter Name="mustfilled" Type="Int32" />
             <asp:Parameter Name="issinglerow" Type="Int32" />
            <asp:Parameter Name="col" Type="Int32" />
            <asp:QueryStringParameter Name="activeid" Type="Int32" QueryStringField="activeid" />
        </UpdateParameters>
      
    
    </asp:SqlDataSource>


    
     
</div>


</div>

</td>

 </tr>
 
 

 
 </table>
























 
 <script>


     $(document).ready(

      function () {

          $("#itemtype").find("input").each(
          function () {

              $(this).click(
              function () {

                  $("#div_optioncount").hide();
                  $("#div_gpblock").hide();
                  $("#cb_issinglerow").prop("checked", false);
                  $("#cb_issinglerow").prop("disabled", false);

                  if ($(this).val() == "RadioButtonList" || $(this).val() == "CheckBoxList") {
                      if ($(this).prop("checked")) {
                          $("#div_optioncount").show();
                      }
                      return;
                  }

                  if ($(this).val() == "GroupOption") {
                      if ($(this).prop("checked")) {
                          $("#div_gpblock").show();
                          $("#cb_issinglerow").prop("checked", true);
                          $("#cb_issinglerow").prop("disabled", true);
                      }
                      else {
                          $("#cb_issinglerow").prop("checked", false);
                          $("#cb_issinglerow").prop("disabled", false);
                      }
                    return;
                  }

              });

          });

      });

      


 </script>

  
</asp:Content>
