我有一个带有约会信息的网格视图。我想做的是在每个单元格中都有一个链接按钮(将在运行时创建)并打开一个显示约会详细信息的模式弹出窗口。任何帮助将不胜感激。
到目前为止,我已经有了,但它不会触发链接按钮
<asp:GridView ID="Grd" runat="server" AutoGenerateColumns="true" onrowdatabound="Grd_RowDataBound"></asp:GridView><asp:Button ID="btnShowPopup" style="display:none" runat="server" />
<ajaxToolkit:ModalPopupExtender
ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup" CancelControlID="ImgCancel" ></ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" Width="400px" ><!--Show Details--!>
<asp:ImageButton ID="imgCancel" AlternateText="cancel" Height="25" Width="25" runat="server" ImageAlign="Right" />
</asp:Panel>
后面的代码
protected void Grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Split out the visit details & format
for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
{
LinkButton lnk = new LinkButton();
lnk.Text = "Details for:" + "<br />" + e.Row.Cells[i].Text;
lnk.CommandName = "ShowDetails";
lnk.Command += LinkButton_Command;
e.Row.Cells[i].Controls.Add(lnk);
}
}
}
protected void LinkButton_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "ShowDetails")
{
LinkButton btndetails = sender as LinkButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
this.ModalPopupExtender1.Show();
}
}