0
我想打開按鈕點擊中繼器上的彈出窗口根據綁定到當前行的id.I寫這個javascript函數,我想根據行ID調用這是唯一的。然後這個java腳本函數從中繼器的ItemDataBound事件中調用。如何在Repeater事件的按鈕點擊調用javascript函數Repeater1_ItemDataBound
Button access = (Button)e.Item.FindControl("btnAccess");
access.OnClientClick = "test(" + lblEduCatId + "); return false;";
在頁面上:
This is java script code :
<script type="text/javascript">
function test(lblEduCatId) {
window.onload = function() {
var modal = document.getElementById('myModal');
var btn = document.getElementById("<%=btnAccess.ClientID %>").value;
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
}
}
</script>
.cs code
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string lblEduCatId = DataBinder.Eval(e.Item.DataItem, "EduCatId").ToString();
string lblIsFree = DataBinder.Eval(e.Item.DataItem, "IsFree").ToString();
string lblAccess = DataBinder.Eval(e.Item.DataItem, "Access").ToString();
Button access = (Button)e.Item.FindControl("btnAccess");
access.OnClientClick = "return test(lblEduCatId);";
if (Session["UserName"] != null)
{
if (lblAccess.ToString() == "True")
{
access.Text = "Access";
access.CommandName = "Access";
}
else
{
access.Text = "Subscribe";
access.CommandName = "Subscribe";
}
}
else
{
if (lblIsFree.ToString() == "True")
{
access.Text = "Access";
access.CommandName = "Access";
}
else
{
access.Text = "Subscribe";
access.CommandName = "Subscribe";
}
}
}
}
感謝您的回答,這有助於解決我的問題。 – Monika