问题描述
有两个日历,一个下拉列表和一个网格视图和按钮。现在我尝试在服务器端访问这些ID
我尝试过:
There is two calendars , one drop down and one grid view and button. Now i try to access these ID's on server side
What I have tried:
<asp:DropDownList ID="regiondrop" runat="server" AutoPostBack="True"
onselectedindexchanged="regiondrop_SelectedIndexChanged">
</asp:DropDownList>
<input ID="fromdate" value="dd/mm/yyyy" runat="server" clientidmode="static" />
<input ID="todate" value="dd/mm/yyyy" runat="server" clientidmode="static" />
<input type="button" id="search_data" class="sear_btn" value="Search Data" />
and gridview
现在我尝试在页面上显示网格视图
为此我试试这个
now i try to display grid view on page
for this i try this
<script type="text/javascript">
$(function () {
var fromdate = $('[ID*=fromdate]').val();
var todate = $('[ID*=todate]').val();
var regiondrop = $('[ID*=regiondrop] option:selected')[0].value;
var GridView1 = $('[ID*=GridView1]');
var obj = {};
obj.fromdate = todate ;
obj.todate = todate ;
obj.regiondrop = regiondrop ;
obj.GridView1 =GridView1 ;
Getdataa(obj);
return false;
});
function Getdataa(obj) {
//alert('1');
$.ajax({
type: "POST",
url: "WebForm1.aspx/search_data",
data: "{'fromdate':'" + fromdate + "','todate':'" + todate + "','regiondrop':'" + regiondrop + "','GridView1':'" + GridView1 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (result) {
$("#GridView1").empty();
if(data.d.length>0){
$("#GridView1").append(
"<tr><th>OName</th><th>RegNo</th>><th>Speed</th>");
for(var i=0;i<data.d.length;i++){
$("#GridView1").append("<tr><td>" +
data.d[i].OName + "</td> <td>" +
data.d[i].RegNo + "</td> <td>" +
data.d[i].Speed + "</td></tr>");
}
}
},
error: function (error) {
alert("error");
}
});
}
对于访问ID,我尝试获取ID,然后我在webmethod函数中传递这些ID这是
For access ID's i try to get ID and then i pass these ID in webmethod function like ths
[WebMethod]
public static string search_data(DateTime fromdate, DateTime todate, string regiondrop)
{
try
{
DateTime frmdate =
Convert.ToDateTime(fromdate.Value.Trim().Split('T')[0]);
DateTime tdatee =
Convert.ToDateTime(todate.Value.Trim().Split('T')[0]);
string regionvalue = Convert.ToString(regiondrop.SelectedValue);
TrackDataEntities1 ts = new TrackDataEntities1();
// here dq code is like this var dq= and here i write LINQ query
//i don't paste because of long query
GridView1.DataSource = dq;
GridView1.DataBind();
}
catch (Exception)
{
GridView1.Visible = false;
Label4.Text = ("No Data");
}
}
当我试试这个节目时错误
错误2'System.DateTime'不包含'Value'的定义,也没有扩展方法'Value'接受类型'System.DateTime的第一个参数'可以找到(你错过了使用指令或程序集引用吗?)
错误3'System.DateTime'不包含'Value'的定义没有扩展方法'Value'接受类型'System.DateTime'的第一个参数可以找到(你是否缺少using指令或汇编引用?)
错误4'字符串'不包含'SelectedValue'的定义,并且没有扩展方法'SelectedValue'接受类型'string'的第一个参数可以找到(你是否缺少using指令或汇编引用?)
错误5非静态字段方法需要对象引用或者属性'chart_project.WebForm1.GridView1'
错误8非静态字段,方法或属性'chart_project.WebForm1.Label4需要对象引用'
任何解决方案
when i try this show errors
Error 2 'System.DateTime' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
Error 3 'System.DateTime' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
Error 4 'string' does not contain a definition for 'SelectedValue' and no extension method 'SelectedValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Error 5 An object reference is required for the non-static field, method, or property 'chart_project.WebForm1.GridView1'
Error 8 An object reference is required for the non-static field, method, or property 'chart_project.WebForm1.Label4'
any solution
推荐答案
这篇关于从客户端到服务器端的访问ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!