ModalPopupExtender open onclick of GridView row problems

时光怂恿深爱的人放手 提交于 2019-12-13 04:27:29

问题


(I'm using Lukinha RS's solution to the row onclick functionality)

When I click on a row within the gridview I get a postback before the ModalPopupExtender opens, I dont want the postback however as you see the method I use is the cause. Unfortunatly it is the only way I have been able to get an onClick applied to a gridview row to open the MPE.

Another problem I have is with the MPE open - I click a 'close' button on the popup panal it simply reloads the page resulting with the same popup panal opening.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    GridViewRow row = e.Row;
    if (row.DataItem == null)
    {
        return;
    }

    try
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.Header:
                break;

            case DataControlRowType.DataRow:
                e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'");
                e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString()));
                break;
        }
    }

    catch
    {
        return;
    }

And here is my SelectedIndexChanged

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = ((GridView)sender).SelectedRow;
    ModalPopupExtender mpe = (ModalPopupExtender)row.FindControl("ModalPopupExtender1");
    mpe.Show();
}

回答1:


Unfortunatly it is the only way I have been able to get an onClick applied to a gridview row to open the MPE

Incorrectly. Actually, you CAN open modal extender without postback. Change onclick attribute value as below:

e.Row.Attributes.Add("onclick", String.Format("javascript:$find('{0}').show();", ModalPopupExtender1.ClientID));


来源:https://stackoverflow.com/questions/12973320/modalpopupextender-open-onclick-of-gridview-row-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!