2017-07-13 70 views
0

我真的很难与此,我发现一个很好的日期范围选择器,使用Jquery的问题是我需要抓住已输出到按钮的文本,以便我可以查询我的sql数据库。我认为最好的方法是将jquery按钮输出到标签,然后有另一个标题为搜索的按钮来抓取已选择的日期。下面是一些代码JQuery文本标签

<head> 
    <link href="jquery-ui.min.css" rel="stylesheet"> 
    <link href="jquery.comiseo.daterangepicker.css" rel="stylesheet"> 
    <script src="jquery.min.js"></script> 
    <script src="jquery-ui.min.js"></script> 
    <script src="moment.min.js"></script> 
    <script src="jquery.comiseo.daterangepicker.js"></script> 
    <script> 
    $(function() { $("#e1").daterangepicker(); }); 
    </script> 
    </head> 
    <body> 
    <form id="form1" runat="server"> 
    <input id="e1" name="e1"><label for="no">text no</label> <<<Hoping to 
    add 
    the values from "e1 to say Value1.Text 
     <asp:Label ID="Label1" runat="server" Text="Label" name="e1"> 
    </asp:Label> 
    </form>` 

然后当我点击搜索它抓住的日期范围,并把它放到我的查询:

 protected void Search_Click(object sender, EventArgs e) 
     { 
     string testdb = 
     ConfigurationManager.ConnectionStrings["easystone"].ConnectionString; 
     SqlConnection con = new SqlConnection(testdb); 
     SqlDataAdapter graph = new SqlDataAdapter("SELECT [User], [dateof] 
     FROM [dbo].[chart]where [dateof] >='"+Label1+"' and [dateof] 
     <='"+Label2+"'", 
     con); 
    DataTable graphdata = new DataTable(); 

     graph.Fill(graphdata); 

     chart1.DataSource = graphdata; 


     chart1.ChartAreas["ChartArea1"].AxisX.Title = ""; 
     } 

`

+0

你缺少问题.. – Webruster

回答

0

Label控件不参与回发的与输入控件一样,更改Label的值然后提交表单不会将Label的新值发送到服务器。

你可以做的是使用HiddenField control,在javascript中设置它的值以匹配日期选择器输入中选择的日期,当其值改变时,然后在你的Search_Click处理器中提取它的值。

或者,您可以将runat="server"ClientIDMode="Static"属性添加到输入中,然后使用e1.Value直接从表单提交中的输入中提取值。

+0

你能给我一个替代路线的例子吗?我试过了,但它没有抓取任何东西,我是否需要将我的搜索按钮放在更新面板中? – Marcus