Sie Bootstrap verwenden könnte das modale Popup angezeigt werden, alles, was Sie tun müssen, ist diese drei Referenzen zu Ihrem Projekt hinzufügen:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
Komplettlösung
-Code hinter:
public class MyFile
{
public int fileid { get; set; }
public string filename { get; set; }
}
public partial class PopupInGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var f1 = new MyFile { fileid = 1, filename = "File 1" };
var f2 = new MyFile { fileid = 2, filename = "File 2" };
var files = new List<MyFile> { f1, f2 };
FileTableView.DataSource = files;
FileTableView.DataBind();
}
}
protected void File_Command(object sender, CommandEventArgs e)
{
string command = e.CommandName;
string fileId = Session["fileid"] as string;
switch (command)
{
case "ShowPopup":
Session["fileid"] = e.CommandArgument;
ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "showPopup();", true);
break;
case "Delete":
//Your delete logic...
break;
case "Download":
//Your download logic...
break;
}
}
}
unten gefunden
.ASPX:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript">
function showPopup() {
$('#myModal').modal('show');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView
ID="FileTableView"
CssClass="datagrid"
HeaderStyle-CssClass="datagridHeader"
RowStyle-CssClass="datagridRows"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="fileid, filename">
<Columns>
<asp:TemplateField HeaderText="Master Folder">
<ItemTemplate>
<asp:LinkButton ID="lnkChoice" CommandName="ShowPopup" OnCommand="File_Command" CommandArgument='<%# Eval("fileid") %>' runat="server" Text='<%# Eval("filename") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Delete or download?</h4>
</div>
<div class="modal-body">
<asp:Button ID="btnDelete" CommandName="Delete" CommandArgument="" runat="server" Text="Delete" OnCommand="File_Command" />
<asp:Button ID="btnDownload" CommandName="Download" CommandArgument="" runat="server" Text="Download" OnCommand="File_Command" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</body>
ich auf eigene Faust ein neues Projekt versucht .. aber wenn ich zu meinem Hauptprojekt übertragen über sie nicht die Pop-up scheint, habe ich System.Diagnostics.Debug.WriteLine ("Prüfung"); im Switch-Fall für Showpopup und tatsächlich wurde Test auf der Ausgabekonsole gedruckt. Das Popup-Fenster wurde jedoch nicht auf meiner Seite angezeigt. Was könnte der Grund dafür sein? –
Ich habe es in meiner Antwort erwähnt. Sie müssen drei Referenzen auf Ihre Seite hinzufügen - jQuery, bootstrap.js und bootstrap.css (in dieser Reihenfolge). Auch müssen Sie sicherstellen, dass Sie ein div mit einer ID = haben "myModal". Eine andere Sache, die ein Problem sein könnte, ist, dass die showPopup() - Funktion nicht innerhalb des jQuery-Dokuments load event definiert werden sollte. Sie sollten es außerhalb des load-Ereignisses platzieren. Stellen Sie sicher, dass Sie alle diese Dinge überprüft haben und es sollte Arbeit.Vergessen Sie zu markieren, wie beantwortet, wenn es Ihnen geholfen –
Ja, ich habe alle Schritte gemacht und es immer noch nicht erscheint, scheint es immer zu aktualisieren, wenn ich auf die Schaltfläche geklickt. –