问题
(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