弹出层,当前页面更新功能
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:ModalPopupExtender ID="pme" runat="server"
TargetControlID="btnJia"
CancelControlID="lbtnClose" DropShadow="false"
PopupControlID="pan1" BackgroundCssClass="bgs"/>
<asp:Button ID="btnJia" runat="server" Text="Button" style="display:none;"/>
<table class="tbList" border="1" bordercolor="#CCCCCC" cellspacing="1" cellpadding="0">
<asp:Repeater ID="rptStyleType" DataSourceID="odsAllAim" runat="server">
<HeaderTemplate>
<thead>
<tr class="trHead">
<th class="tdID">编号</th>
<th class="tdKeyeDesc">意向描述</th>
<th class="tdSubEdit">更改</th>
<th class="tdDel">删除</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr class="trItem">
<td class="tdItemID"><%# Eval("AID") %></td>
<td><%# Eval("A_Desc")%></td>
<td class="tdSetMid">
<asp:LinkButton ID="btnOpensMoup" runat="server" CommandArgument='<%# Eval("AID")%>' CommandName="SetOpenMoup" OnCommand="lbtnEdit_Command">更新</asp:LinkButton>
</td>
<td class="tdSetMid">
<asp:LinkButton ID="lbtnDel" CommandArgument='<%# Eval("AID")%>' CommandName="SetDel" runat="server" OnCommand="lbtnEdit_Command">删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<p class="pHr"> </p>
<!--添加新项 start-->
添加新项:<asp:TextBox ID="txtNewAim" runat="server"></asp:TextBox>
<asp:Button ID="btnAddItem" runat="server" Text="添加新项"
onclick="btnAddItem_Click" />
<!--添加新项 end-->
<!--弹出层pan1 start-->
<asp:Panel ID="pan1" runat="server" style="display:none;">
<asp:DetailsView ID="dvAimDetail" runat="server" Height="50px" Width="125px"
EnableModelValidation="True" AutoGenerateRows="False"
DataSourceID="odsGetAimByAID">
<Fields>
<asp:TemplateField SortExpression="A_Desc">
<ItemTemplate>
<asp:TextBox ID="txtDesc" runat="server" Text='<%# Bind("A_Desc") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:LinkButton ID="lbtnSave" CommandName="SetSave" runat="server" onclick="lbtnSave_Click">保存</asp:LinkButton>
<asp:LinkButton ID="lbtnClose" runat="server">取消</asp:LinkButton>
</asp:Panel>
<!--弹出层pan1 end-->
<!--ObjectDataSource start-->
<asp:ObjectDataSource ID="odsGetAimByAID" runat="server"
SelectMethod="GetAimByAID" TypeName="Crm.BLL.AimManage">
<SelectParameters>
<asp:SessionParameter Name="aid" SessionField="aid" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsAllAim" runat="server" SelectMethod="GetAllAim"
TypeName="Crm.DAL.SQL.AimService"></asp:ObjectDataSource>
<!--ObjectDataSource end-->
</form>
二、后台
protected void lbtnEdit_Command(object sender, CommandEventArgs e)
{
string cmdName = e.CommandName;
int id =Convert.ToInt32(e.CommandArgument);
switch (cmdName)
{
case "SetDel":
break;
case "SetOpenMoup":
OpenMpeSetSession(id);
break;
default:
break;
}
}
/// <summary>
/// 打开弹出层,存入ID至Session
/// </summary>
/// <param name="aid"></param>
protected void OpenMpeSetSession(int aid)
{
pme.Show();
Session["aid"]=aid;
}
/// <summary>
/// 更新、清楚session
/// </summary>
protected void ExecSaveAction()
{
int aid=(int)Session["aid"];
TextBox txt = dvAimDetail.FindControl("txtDesc") as TextBox;
MD_Aim aim = new MD_Aim();
aim.AID = aid;
aim.A_Desc = txt.Text;
int result = aimManage.UpdateAimByAID(aim);
if (result>0)
{
Session.Remove("aid");
pme.Hide();
ShowMsgUrl("WebForm1.aspx");
}
else
{
Session.Remove("aid");
pme.Hide();
ShowMsg("更新失败","WebForm1.aspx");
}
}
/// <summary>
/// 保存并更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnSave_Click(object sender, EventArgs e)
{
ExecSaveAction();
}
/*-------------------------------JS输出提示 Start------------------------------------*/
public void ShowMsg(string msg, string url)
{
Response.Write("<script language=javascript>alert('" + msg + "');</script>");
//Page.ClientScript.RegisterClientScriptBlock(GetType(), "msgs", "alert('" + msg + "');", true);
Response.Write("<script language=javascript>window.location.href='" + url + "';</script>");
}
public void ShowMsg(string msg)
{
Response.Write("<script language=javascript>alert('" + msg + "');</script>");
}
public void ShowMsg(int strInt, string url)
{
string msg = strInt.ToString();
Response.Write("<script language=javascript>alert('" + msg + "');</script>");
//Page.ClientScript.RegisterClientScriptBlock(GetType(), "msgs", "alert('" + msg + "');", true);
Response.Write("<script language=javascript>window.location.href='" + url + "';</script>");
}
public void ShowMsgUrl(string url)
{
Response.Write("<script language=javascript>window.location.href='" + url + "';</script>");
}
public void ShowMsg(int strInt)
{
string msg = strInt.ToString();
Response.Write("<script language=javascript>alert('" + msg + "');</script>");
}
protected void btnAddItem_Click(object sender, EventArgs e)
{
MD_Aim aim = new MD_Aim();
aim.A_Desc = txtNewAim.Text;
aimManage.AddAim(aim);
ShowMsgUrl("WebForm1.aspx");
}