页面取值

JS脚本的编写和页面传值方式给我的印象都是些细小琐碎的麻烦事!

前天做的一个页面功能分享一下:

引入命名空间:

using Microsoft.Practices.EnterpriseLibrary.Data;//微软的一个代码插件
using Model;
using System.Collections.Generic;

CS代码:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            MyBind();
    }

    protected void MyBind()
    {
        BLL.Quest_Index_AnswerBll tb = new BLL.Quest_Index_AnswerB();                                Repeater1.DataSource = tb .Select ();
        Repeater1.DataBind();
    }
    protected DataTable  Bind()
    {
       BLL.Quest_Index_AnswerBll  tb = new BLL.Quest_Index_AnswerBll ();

         return tb.Select();        
    }
    /// <summary>
    /// 获取答案
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    public string Anther(string s,int option_type)
    {
        BLL.Quest_Index_AnswerBll tb = new BLL.Quest_Index_AnswerBll();
        string str = "<table >";
        tb.Select(s );

        for (int i = 0; i < tb.Select(s).Rows.Count ; i++)
        {
            if (option_type==1)
            {
                str += "<tr><td > <input runat=\"server\" id=\"Radio" + i + "\" type=\"radio\" name =\"" + s  + "\" value =\"" + tb.Select(s).Rows[i]["score"] + "\" />" + tb.Select(s).Rows[i]["option_name"] + " </td></tr>";
            }
            if (option_type == 2)
            {
                str += "<tr><td > <input runat=\"server\" id=\"Radio" + i + "\" type=\"radio\" name =\"" + i + "\" value =\"" + tb.Select(s).Rows[i]["score"] + "\" />" + tb.Select(s).Rows[i]["option_name"] + " </td></tr>";
            }
        }
        str += "</table>";
        return str;
    }


 protected void Button1_Click(object sender, EventArgs e)
    {
        BLL.Quest_Index_AnswerBll QIA = new BLL.Quest_Index_AnswerBll();
        string c = Hidden1.Value;
        string c1 = Hidden2.Value;
        Quest_Index_Answer cj = new Quest_Index_Answer();
        List<Quest_Index_Answer> sc = new List<Quest_Index_Answer>();
        string[] s = c.Split(',');
        string[] m = c1.Split(',');

        for (int i = 0; i < s.Length; i++)
        {
            cj.Index_Id = m[i];
            cj.Score_Eva = double .Parse (s[i]);
            cj.Emmployee_Id = "111111";
            cj.Quest_Index_Answer_Id = "555";

            sc.Add(cj);
        }

        QIA.Addlist(sc);

    }

前台代码:

<form id="form1" runat="server">
    <div  align="right">
      <asp:Repeater ID="Repeater1" runat="server" >
                            <ItemTemplate>
                           
                                <table width="90%" >
                                    <tr  align ="left" >  <td >
                                            <%#Eval("problem_desc").ToString ()%>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td align ="left">
                                           <%# Anther(Eval("index_id").ToString(),int .Parse ( Eval("option_type").ToString ()))%>
                                        </td>
                                    </tr>
                                </table>                              
                            </ItemTemplate>
                        </asp:Repeater><br />

    </div>
    <div  align="center"   >

        <asp:button ID="Button1" runat="server" text="保存" Width="62px"  OnClientClick ="sub()" OnClick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="提交" Width="61px" />
        <input id="Hidden1" runat="server" type="hidden" />
        <input id="Hidden2" runat="server" type="hidden" />
        </div>
</form>

JS脚本:

function sub(){
//校验
for(var   i=0;i <document.form1.Options.length;i++){
if(document.form1.Options[i].checked==false)
{
alert( "存在漏选!请仔细检查 ");
document.form1.Options[i].focus();
return   false;
}
else
{
//获取值
    g=document.getElementsByTagName("input");
    var str='';
    var str1='';
    for(var i=0;i<g.length;i++){
        var obj = document.getElementsByName('radio'+i);
          for(var j=0;j<obj.length;j++)  
          {  
          if(obj[j].checked   ==   true)  
          {  
          //记录值
          str+=obj[j].value+',';
          str1+=obj[j].name+',';
          g--;
          } 
        }    
    }    
    document.getElementById("Hidden1").value = str;
    document.getElementById("Hidden2").value = str1;
    if(g==0)alert('提交完成!');
    else alert('提交失败!');}
}
}

你可能感兴趣的:(js,脚本,取值,休闲,js脚本)