我是 EF 和 jQuery 数据表的新手。我有两个实体,称为 Country 和 State。我正在像这样绑定我的国家电网
public void BindGrid()
{
using (var db = new DefaultCS())
{
var query = from c in db.CountryMasters
orderby c.CountryId ascending
select c;
GridView1.DataSource = query.ToList();
GridView1.DataBind();
}
}
和
<script type="text/javascript">
function fnClickRedraw() {
var oTable;
$(document).ready(function () {
TableTools.DEFAULTS.aButtons = ["copy", "csv", "xls", "pdf", "print"]
oTable = $('#<%=GridView1.ClientID %>').dataTable({
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": 10,
"aaSorting": [[0, "asc"]],
"bJQueryUI": true,
"bRetrieve": true, "sPaginationType": "full_numbers",
"sDom": '<"top"i><"title">lt<"bottom"pf>',
// ---- Print_Export_Copy ----
"sDom": 'T<"clear"><"H"lfr>t<"F"ip>', "oTableTools": {
"sSwfPath": "../Content/DataTables-1.9.4/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
},
"bAutoWidth": true
});
oTable.$('tr').hover(function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); });
oTable.$('tr').css("cursor", "pointer");
oTable.$('td').click(function () {
var aPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(aPos[0]);
$.fancybox({
'titleShow': false,
'width': 600,
'height': 460,
'href': 'CountryNew.aspx?Code=' + aData[0] + '',
'type': 'iframe',
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'closeClick': false,
'helpers': {
overlay: {
closeClick: false,
showEarly: false
}
},
'overlayOpacity': 0.7,
'beforeClose': function () { document.getElementById("<%=btnRedraw.ClientID%>").click(); }
});
});
});
/* Get the rows which are currently selected */
function fnGetSelected(oTableLocal) {
return oTableLocal.$('tr.hover');
}
}
function pageLoad(sender, args) {
$("#btnCreate").fancybox({
'titleShow': false,
'width': 600,
'height': 460,
'type': 'iframe',
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'closeClick': false,
'helpers': {
overlay: {
closeClick: false,
showEarly: false
}
},
'overlayOpacity': 0.7,
'enableEscapeButton': false,
'showCloseButton': false,
'beforeClose': function () { document.getElementById("<%=btnRedraw.ClientID%>").click(); }
});
}
</script>
当我在fancybox中单击网格行编辑国家表单时,编辑后我调用了一个隐藏按钮来使用更新面板重新绑定网格。创建新国家的 Sam 程序。我的问题:如何在不使用更新面板的情况下插入新国家?提前致谢。