Asp.net AjaxToolkit ModalPopup扩展器
我正在使用AjaxToolKit,并创建了一个带有详细信息按钮的gridview。我想打开一个面板,在单击“详细信息”按钮时,该面板将有两个以上的GridView,即ModalPopupXtender。它还应突出显示正在编辑的行。 我得到这个错误 网页错误详细信息 消息:无效字符 行:269 字符:7 代码:0 URI: 我检查了设计/源代码和代码,但没有找到任何无效字符。此外,当我在运行时单击“详细信息”按钮时,gridview将消失 有什么建议吗 以下是完整的源代码: HTML部分:Asp.net AjaxToolkit ModalPopup扩展器,asp.net,ajax,gridview,modalpopupextender,Asp.net,Ajax,Gridview,Modalpopupextender,我正在使用AjaxToolKit,并创建了一个带有详细信息按钮的gridview。我想打开一个面板,在单击“详细信息”按钮时,该面板将有两个以上的GridView,即ModalPopupXtender。它还应突出显示正在编辑的行。 我得到这个错误 网页错误详细信息 消息:无效字符 行:269 字符:7 代码:0 URI: 我检查了设计/源代码和代码,但没有找到任何无效字符。此外,当我在运行时单击“详细信息”按钮时,gridview将消失 有什么建议吗 以下是完整的源代码: HTML部分:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style>
.modalBackground
{
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="scriptManager" runat="server" />
<div>
<p style="background-color:AliceBlue; width:95%">
Example of using a
ModalPopupExtender to edit the indivdual rows of a GridView.<br />
To test out the functionality,
click the Details button of any of the rows and watch what happens.<br />
</p>
<br />
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="Customers" BackColor="lightblue" Width="95%" />
<asp:GridView
ID="gvCustomers" runat="server"
AutoGenerateColumns="false"
AllowPaging="true" AllowSorting="true"
PageSize=10 OnPageIndexChanging="myGridView_PageIndexChanging"
OnRowDataBound="Gridview_RowDataBound" EnableViewState="false"
Width="95%">
<AlternatingRowStyle BackColor="AliceBlue"
/>
<HeaderStyle HorizontalAlign="Left"
/>
<Columns>
<asp:TemplateField HeaderText="V">
<ItemTemplate>
<asp:CheckBox ID="chkVerified" runat="server"
Checked='<%# Eval("V") == "True" ? true : false %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NT">
<ItemTemplate>
<asp:CheckBox ID="chkDeleted" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="P">
<ItemTemplate >
<asp:Label ID="P" runat="server" Text='<%# Eval("P") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FN">
<ItemTemplate >
<asp:Label ID="FN" runat="server" Text='<%# Eval("FN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MN" >
<ItemTemplate >
<asp:Label ID="MN" runat="server" Text='<%# Eval("MN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LN" >
<ItemTemplate >
<asp:Label ID="LN" runat="server" Text='<%# Eval("LN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate >
<asp:Label ID="Title" runat="server" Text='<%# Eval("Title") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnViewDetails"
runat="server"
Text="Details"
OnClick="btnViewDetails_Click"
/>
</ItemTemplate>
<ControlStyle Width="50px" />
<HeaderStyle Width="60px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button id="btnShowPopup" runat="server" style="display:none" />
<ajaxToolKit:ModalPopupExtender
ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display:none">
<asp:UpdatePanel ID="updPnlCustomerDetail" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblCustomerDetail" runat="server"
Text="Customer
Detail" BackColor="lightblue" Width="95%" />
<asp:Panel ID="pnlPopupInner" runat="server">
<table>
<tr><td>Test1</td></tr>
<tr><td>Test2</td></tr>
<tr><td>Test3</td></tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div align="right" style="width:95%">
<asp:Button
ID="btnSave" runat="server"
Text="Save"
OnClientClick="alert(’Sorry, but I didnt implement save because I
dont want my northwind database getting messed up.’); return false;"
Width="50px" />
<asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
</div>
</asp:Panel>
</div>
</form>
</body>
</html>
无标题页
莫达尔巴基德先生
{
背景颜色:灰色;
过滤器:α(不透明度=70);
不透明度:0.7;
}
要测试功能,
单击任一行的“详细信息”按钮,观察发生的情况。
测试1
测试2
测试3
代码隐藏:
using System;
using System.Drawing;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MDRTeachersTest; //Webservice
public partial class Default3 : System.Web.UI.Page
{
string sFullName = "";
int firstRow = 0;
private int selectedIndex;
protected void Page_Load(object sender, EventArgs e)
{
sFullName = "";
firstRow = -1;
if (!IsPostBack)
{
bool bTest = loginToWS();
if (bTest == true)
{
gvCustomers.Visible = true;
}
}
}
private bool loginToWS()
{
//code to login to web service and fetch the object filled with data.
}
private static DataTable dtInfoPersonnel(Organization org)
{
string RowId = "";
string PersonId = "";
bool firsttime = true;
DataRow dr;
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("V", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("NT", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("P");
dtTemp.Columns.Add("FN");
dtTemp.Columns.Add("MN");
dtTemp.Columns.Add("LN");
dtTemp.Columns.Add("Title");
dtTemp.Columns.Add("Remove");
dtTemp.Columns.Add("Vacant", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("Status");
dtTemp.Columns.Add("RowId");
dtTemp.Columns.Add("PersonId");
dtTemp.Columns.Add("Verified", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("Substitute", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("ComputerUser", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("YearsExperience");
dtTemp.Columns.Add("Closed", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("AP", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("CU", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("PF", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("historicAlphaCode");
foreach (K12Personnel person in org.persons)
{
//Code to fill DATATABLE with the data.
}
return dtTemp;
}
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(gvCustomers, "Select$" + e.Row.RowIndex.ToString()));
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);
if (sFullName == drv["FN"].ToString() + drv["LN"].ToString())
{
//If it's the same category as the previous one
//Increment the rowspan
for (int cellCount = 0; cellCount < 6; cellCount++)
{
if (gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan == 0)
gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan = 2;
else
gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan += 1;
//Remove the cell
e.Row.Cells.RemoveAt(0);
}
}
else //It's a new category
{ //Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
sFullName = drv["FN"].ToString() + drv["LN"].ToString();
firstRow = e.Row.RowIndex;
}
}
}
catch (Exception ex)
{
}
}
protected void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dtTemp1 = new DataTable();
dtTemp1 = (DataTable)Session["PersonnelInfo"];
dtTemp1.DefaultView.Sort = "LN " + "ASC";
gvCustomers.DataSource = dtTemp1;
gvCustomers.PageIndex = e.NewPageIndex;
gvCustomers.DataBind();
}
protected void btnViewDetails_Click(object sender, EventArgs e)
{
this.updPnlCustomerDetail.Update();
this.mdlPopup.Show();
}
使用系统;
使用系统图;
使用系统数据;
使用系统配置;
使用系统集合;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Web.UI.WebControl.WebParts;
使用System.Web.UI.HTMLControl;
使用MDRTeachersTest//介绍
公共部分类Default3:System.Web.UI.Page
{
字符串sFullName=“”;
int firstRow=0;
私有int-selectedIndex;
受保护的无效页面加载(对象发送方、事件参数e)
{
sFullName=“”;
第一行=-1;
如果(!IsPostBack)
{
bool bTest=loginToWS();
如果(bTest==true)
{
gvCustomers.Visible=true;
}
}
}
私有bool loginToWS()
{
//用于登录到web服务并获取填充有数据的对象的代码。
}
私有静态数据表dtInfoPersonnel(组织组织)
{
字符串RowId=“”;
字符串PersonId=“”;
bool firsttime=true;
数据行dr;
DataTable dtTemp=新DataTable();
添加(“V”,System.Boolean.FalseString.GetType());
dtTemp.Columns.Add(“NT”,System.Boolean.FalseString.GetType());
dtTemp.列添加(“P”);
dtTemp.列添加(“FN”);
dtTemp.列添加(“MN”);
dtTemp.列添加(“LN”);
dtTemp.列添加(“标题”);
dtTemp列。添加(“删除”);
添加(“空”,System.Boolean.FalseString.GetType());
dtTemp列添加(“状态”);
dtTemp.Columns.Add(“RowId”);
dtTemp.Columns.Add(“PersonId”);
添加(“已验证”,System.Boolean.FalseString.GetType());
添加(“替换”,System.Boolean.FalseString.GetType());
添加(“ComputerUser”,System.Boolean.FalseString.GetType());
dtTemp列添加(“年经验”);
dtTemp.Columns.Add(“Closed”,System.Boolean.FalseString.GetType());
添加(“AP”,System.Boolean.FalseString.GetType());
添加(“CU”,System.Boolean.FalseString.GetType());
添加(“PF”,System.Boolean.FalseString.GetType());
dtTemp.Columns.Add(“历史密码”);
foreach(组织人员中的K12人员)
{
//用数据填充数据表的代码。
}
返回dtTemp;
}
受保护的void Gridview_RowDataBound(对象发送方,GridViewRowEventArgs e)
{
尝试
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
//e、 添加(“onclick”,Page.ClientScript.GetPostBackEventReference(gvCustomers,“Select$”+e.Row.RowIndex.ToString());
//我们只对包含数据的行感兴趣
//获取用于数据绑定行的数据的引用
DataRowView drv=((DataRowView)e.Row.DataItem);
如果(sFullName==drv[“FN”].ToString()+drv[“LN”].ToString())
{
//如果它与前一个类别相同
//增加行间距
对于(int-cellCount=0;cellCount<6;cellCount++)
{
if(gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan==0)
gvCustomers.Rows[firstRow]。Cells[cellCount]。RowSpan=2;
其他的
gvCustomers.Rows[firstRow]。Cells[cellCount]。RowSpan+=1;
//取出电池
e、 行。单元格。移除(0);
}
}
否则//这是一个新的类别
{//将垂直对齐设置为顶部
e、 Row.VerticalAlign=VerticalAlign.Top;
//在内存中维护该类别
sFullName=drv[“FN”].ToString()+drv[“LN”].ToString();
firstRow=e.Row.RowIndex;
}
}
}
捕获(例外情况除外)
{
}
}
受保护的无效myGridView\u页面索引交换(对象发送方,GridViewPageEventArgs e)
{
DataTable dtTemp1=新DataTable();
dtTemp1=(数据表)会话[“PersonnelInfo”];
dtTemp1.DefaultView.Sort=“LN”+“ASC”;
gvCustomers.DataSource=dtTemp1;
gvCustomers.PageIndex=e.NewPageIndex;
gvCustomers.DataBind();
}
受保护的无效btnViewDetails\u单击(对象发送者,事件参数e)
{
this.updPnlCustomerDetail.Update();
this.mdlPopup.Show();
}
当我运行代码时。它确实会显示gridview,但我在浏览器的左下角看到一个错误“无效字符”。页面可以工作,但当我单击
OnClientClick="alert(’Sorry, but I didnt implement save because I dont want my northwind database getting messed up.’); return false;"