0
實際上,我將JSON字符串傳遞給該腳本,並希望將其顯示在detailsview中。將JSON字符串數據綁定到詳細信息視圖
這是我的jQuery是什麼樣子
function onBeforeClientInsert(record) {
var eventtype = parseInt(record.<%= CEO.FieldEvaluator.GetEvaluatorByDId("EVENT_TYPE_ID").GetFieldDataFieldId()%>);
var begindate = record.<%= CEO.FieldEvaluator.GetEvaluatorByDId("BeginDate").GetFieldDataFieldId()%>;
var enddate = record.<%= CEO.FieldEvaluator.GetEvaluatorByDId("EndDate").GetFieldDataFieldId()%>;
$.ajax({
type: "POST", url: "Data.aspx/CheckInsertRecord",
data: "{EventType:'" + eventtype + "',BeginDate:'" + begindate + "'," +
"EndDate:'" + enddate+"' }",
contentType: "application/json; charset=utf-8", dataType: "json",
success: function (msg) {
if(msg.d == "No duplicate"){
}
else{
alert(msg.d);
eval("var data = "+msg.d+";");
alert(data[0].BeginDate);
alert(data[0].EVENT_TYPE_ID);
}
var modal = document.getElementById('Div1');
modal.style.display = '';
modal.style.position = 'fixed';
modal.style.zIndex = '100';
modal.style.left = '30%';
modal.style.top = '40%';
var screen = document.getElementById('modalScreen');
screen.style.display = '';
}
});
modalScreen只是創建了一個彈出窗口。這是Div1構成由
<div style="display: none; background-color: White; width: 450px; height: 150px;"
id="Div1">
<asp:Label ID="Label1" Text="HI" runat="server"></asp:Label>
<asp:DetailsView ID="de" runat="server" AutoGenerateRows="True" Height="50px" Width="301px">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval(data[0].EVENT_TYPE_ID) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<input type="button" onclick="Hide()" value="OK" />
</div>
這是mycodebehind:
public static string CheckInsertRecord(String EventType, String BeginDate, String EndDate)
{
NCDCPoint ncdc = new NCDCPoint();
CEOSurveyDataContext CDC = new CEOSurveyDataContext();
int et = Convert.ToInt32(EventType);
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime b = Convert.ToDateTime(BeginDate);
DateTime e = Convert.ToDateTime(EndDate);
DetailsView a = new DetailsView();
var query = (from n in CDC.NCDCPoints
where n.EVENT_TYPE_ID == et && n.BeginDate == b && n.EndDate == e
select new {
n.EVENT_TYPE_ID,
BeginDate = n.BeginDate.ToString("yyyy-MM-dd",provider),
EndDate = n.EndDate.ToString(),
n.BeginLAT,
BeginLONG = n.BeginLONG,
n.EndLAT,
n.EndLONG});
if (query.Any())
{
return new JavaScriptSerializer().Serialize(query.ToList());
}
else
{
return "No duplicate";
}
}
所以,我不能訪問內部Div1構成數據變量。那麼你們可以讓我知道我可以如何處理這個問題嗎?
此外,我在代碼隱藏中編寫的查詢是我需要顯示的內容?那麼,你能找到任何其他方式來做到這一點嗎?
我只是試過你告訴我的方式,但我無法得到指示值 – Sayamima
k .....剛剛看到你的更新謝謝你.... – Sayamima