我有兩個gridview。點擊一個網格的一行,我必須填充另一個gridview。所以onClientclick的JavaScript函數,我叫ajax返回數據表填充另一個網格。現在我堅持如何使用JavaScript綁定網格視圖。使用Ajax填充Gridview
這裏是代碼
<asp:gridview id="gridview1"> .....</asp:gridview>
<asp:gridview id="gridview2"> .....</asp:gridview>
代碼隱藏
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton db = (LinkButton)e.Row.Cells[0].Controls[0];
db.OnClientClick = "FunPopulateSecondGrid(" + CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, Label).text + ");"
}
}
的JavaScript
function FunPopulateSecondGrid(productid)
{
$.ajax({
url : '...',
data : { getExEmpList: true, SelectedShop : selectedShop, ajaxCall : true },
method : 'GET',
dataType : 'json',
contentType: "application/json; charset=utf-8",
success : function(data) {
// i am stuck here how to bind it
//gridview2.datasource= data
//gridview2.databind()
},
error : function(xhr, status) {
alert('Sorry, there was a problem while placing your ajax request. Contact Admin!');
}
});
}
謝謝,我會嘗試,並會讓你今天知道EOD。 –