Asp.net模态DataGridView [英] Asp.net Modal DataGridView

查看:56
本文介绍了Asp.net模态DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Title =Language =C#MasterPageFile =〜/ Principal.MasterAutoEventWireup =trueCodeBehind =PesquisarUnidade.aspx.csInherits =AgendamentoOnLine.PesquisarUnidade%>



<%@ Register Assembly =AjaxControlToolkitNamespace =AjaxControlToolkitTagPrefix =asp%>

< asp :Content ID =Content1ContentPlaceHolderID =headrunat =server>



< asp:Content ID =Content2ContentPlaceHolderID =ContentPlaceHolder1 runat =server>



< form id =frmPesquisarUnidaderunat =server>

< link href =css / StyleSheet.css =stylesheet/>

< script src =Scripts / jquery-1.3.2.min.js>< / script>

< script src =Scripts / jquery.blockUI.js>< / script>



< script type = text / javascript>

函数BlockUI(elementID){

var prm = Sys.WebForms.PageRequestManage r.getInstance();

prm.add_beginRequest(function(){

$(#+ elementID)。block({

消息:'

'+

'< img src =imagens / loadingAnim.gif/>
',

css:{},

overlayCSS:{

backgroundColor:'# 000000',不透明度:0.8

}

});

});

prm.add_endRequest(功能(){

$(#+ elementID).unblock();

});

}

$(document).ready(function(){



BlockUI(<%= pnlAddEdit.ID%>);

$ .blockUI.defaults.css = {};

});

函数Hidepopup(){

$ find(popup)。hide();

返回false;

}

< / script>



<%@ Page Title="" Language="C#" MasterPageFile="~/Principal.Master" AutoEventWireup="true" CodeBehind="PesquisarUnidade.aspx.cs" Inherits="AgendamentoOnLine.PesquisarUnidade" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<form id="frmPesquisarUnidade" runat="server">
<link href="css/StyleSheet.css" rel="stylesheet" />
<script src="Scripts/jquery-1.3.2.min.js"></script>
<script src="Scripts/jquery.blockUI.js"></script>

<script type = "text/javascript">
function BlockUI(elementID) {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(function () {
$("#" + elementID).block({
message: '

' +
'<img src="imagens/loadingAnim.gif"/>
',
css: {},
overlayCSS: {
backgroundColor: '#000000', opacity: 0.8
}
});
});
prm.add_endRequest(function () {
$("#" + elementID).unblock();
});
}
$(document).ready(function () {

BlockUI("<%=pnlAddEdit.ID %>");
$.blockUI.defaults.css = {};
});
function Hidepopup() {
$find("popup").hide();
return false;
}
</script>



< asp:ScriptManager ID =ScriptManager1runat =server>





< asp:UpdatePanel ID =UpdatePanel1runat =server>

< contenttemplate>

< asp:GridView ID =GridViewUnidaderunat =serverWidth =550pxAutoGenerateColumns =falseAlternatingRowStyle-BackColor =white

HeaderStyle-BackColor =黑色AllowPaging =truePageSize =10>

< columns> < asp:BoundField DataField =IDHeaderText =IDHtmlEncode =true/>

< asp:BoundField DataField =UnidadeNameHeaderText =UnidadeNameHtmlEncode =true />

< asp:BoundField DataField =LogradouroHeaderText =LogradouroHtmlEncode =true/>

< asp:BoundField DataField = NumeroHeaderText =NumeroHtmlEncode =true/>

< asp:BoundField DataField =ComplementoHeaderText =ComplementoHtmlEncode =true/>

< asp:BoundField DataField =BairroHeaderText =BairroHtmlEncode =true/>

< asp:BoundField DataField =CidadeHeaderText =Cidade HtmlEncode =true/>

< asp:BoundField DataField =EstadoHeaderText =EstadoHtmlEncode =true/>

< asp:TemplateField ItemStyle-Width =70pxHeaderText =ID>

< itemtemplate>

< asp:LinkBut​​ton ID = lnkEditrunat =serverText =EditOnClick =Editar>





< alternatingrowstyle backcolor =白色>





< asp:Panel ID =pnlAddEditrunat =serverCssClass =modalPopupstyle = display:none>

< asp:Label Font-Bold =trueID =lblTitulorunat =serverText =Dados da Unidade>






< asp:Label ID = lblIDrunat =serverText =N°Unidade>

< asp:TextBox ID =txtIDWidth =40pxMaxLength =5 runat =server>

< asp:Label ID =lblUnidadeNamerunat =serverText =Unidade >

< asp:TextBox ID =txtUni dadeNamerunat =server>

< asp:Label ID =lblLogradourorunat =serverText =Logradouro>

< asp:TextBox ID =txtLogradourorunat =server>

< asp:Label ID =lblNumerorunat =serverText =Numero>

< asp:TextBox ID =txtNumerorunat =server >

< asp:Label ID =lblComplementorunat =serverText =Complemento>

< asp:TextBox ID =txtComplementorunat =server>

< asp:Label ID =lblBairrorunat =serverText =Bairro>

< asp:TextBox ID =txtBairrorunat =server>

< asp:Label ID = lblCidaderunat =serverText =Cidade>

< asp:TextBox ID =txtCidaderunat =server>

< asp:Label ID =lblEstadorunat =serverText =Estado>

< asp:TextBox ID =txtEstadorunat =server>

< asp:按钮ID =btnSaverunat =serverText =SaveOnClick =Save/>

< asp:Button ID =btnCancelrunat = serverText =取消OnClientClick =返回Hidepopup()/>





< asp:LinkBut​​ton ID =lnkFakerunat =server>

< asp:ModalPopupExtender ID =popuprunat =serverdropshadow = falsepopupcontrolid =pnlAddEdittargetcontrolid =lnkFakebackgroundcssclass =modalBackground>





< triggers> < asp:AsyncPostBackTrigger ControlID =GridViewUnidade/>

< asp:AsyncPostBackTrigger ControlID =btnSave/>






<asp:ScriptManager ID="ScriptManager1" runat="server">


<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<contenttemplate>
<asp:GridView ID="GridViewUnidade" runat="server" Width="550px" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="white"
HeaderStyle-BackColor="black" AllowPaging="true" PageSize="10" >
<columns> <asp:BoundField DataField="ID" HeaderText = "ID" HtmlEncode = "true" />
<asp:BoundField DataField="UnidadeName" HeaderText="UnidadeName" HtmlEncode = "true" />
<asp:BoundField DataField="Logradouro" HeaderText="Logradouro" HtmlEncode = "true"/>
<asp:BoundField DataField="Numero" HeaderText="Numero" HtmlEncode = "true"/>
<asp:BoundField DataField="Complemento" HeaderText="Complemento" HtmlEncode = "true"/>
<asp:BoundField DataField="Bairro" HeaderText="Bairro" HtmlEncode = "true"/>
<asp:BoundField DataField="Cidade" HeaderText="Cidade" HtmlEncode = "true"/>
<asp:BoundField DataField="Estado" HeaderText="Estado" HtmlEncode = "true"/>
<asp:TemplateField ItemStyle-Width = "70px" HeaderText = "ID">
<itemtemplate>
<asp:LinkButton ID="lnkEdit" runat="server" Text = "Edit" OnClick="Editar">


<alternatingrowstyle backcolor="White">


<asp:Panel ID="pnlAddEdit" runat="server" CssClass="modalPopup" style= "display:none">
<asp:Label Font-Bold="true" ID="lblTitulo" runat="server" Text="Dados da Unidade" >



<asp:Label ID = "lblID" runat = "server" Text = "N° Unidade" >
<asp:TextBox ID="txtID" Width = "40px" MaxLength = "5" runat="server">
<asp:Label ID = "lblUnidadeName" runat = "server" Text = "Unidade" >
<asp:TextBox ID="txtUnidadeName" runat="server">
<asp:Label ID = "lblLogradouro" runat = "server" Text="Logradouro" >
<asp:TextBox ID="txtLogradouro" runat="server">
<asp:Label ID = "lblNumero" runat = "server" Text = "Numero" >
<asp:TextBox ID="txtNumero" runat="server">
<asp:Label ID = "lblComplemento" runat = "server" Text="Complemento" >
<asp:TextBox ID="txtComplemento" runat="server">
<asp:Label ID = "lblBairro" runat = "server" Text = "Bairro" >
<asp:TextBox ID="txtBairro" runat="server">
<asp:Label ID = "lblCidade" runat = "server" Text = "Cidade" >
<asp:TextBox ID="txtCidade" runat="server">
<asp:Label ID = "lblEstado" runat = "server" Text = "Estado" >
<asp:TextBox ID="txtEstado" runat="server">
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="Save" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="return Hidepopup()"/>


<asp:LinkButton ID="lnkFake" runat="server">
<asp:ModalPopupExtender ID="popup" runat="server" dropshadow="false" popupcontrolid="pnlAddEdit" targetcontrolid="lnkFake" backgroundcssclass="modalBackground">


<triggers> <asp:AsyncPostBackTrigger ControlID="GridViewUnidade" />
<asp:AsyncPostBackTrigger ControlID="btnSave" />




< / form>





使用系统;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Configuration;

使用System.Data ;

使用System.Data.SqlClient;

使用System.Text;



命名空间AgendamentoOnLine

{

公共部分类PesquisarUnidade:System.Web.UI.Page

{

private String strConnString = ConfigurationManager.ConnectionStrings [AgendamentoOnLine.Properties.Settings.Setting]。ConnectionString;



protected void Page_Load(object sender,EventArgs e)

{

if(!IsPostBack)

{

Bind();

}

}



protected void Bind()

{

string strQuery =select ID,UnidadeName,Logradouro, Numero,Complemento,Bairro,Cidade,Estado来自tb_unidade;

SqlCommand cmd = new SqlCommand(strQuery);

GridViewUnidade.DataSource = GetData(cmd);

GridViewUnidade.DataBind();

}



私有DataTable GetData(SqlCommand cmd)

{

DataTable dt = new DataTable();

using(SqlConnection con = new SqlConnection(strConnString))

{

使用(SqlDataAdapter sda = new SqlDataAdapter())

{

cmd.Connection = con;

con.Open();

sda.SelectCommand = cmd;

sda.Fill(dt);

return dt;

}

}

}



protected void GridViewData_RowCommand(object sender,GridViewCommandEventArgs e)< br $>
{



}





受保护void Add(object sender,EventArgs e)

{





}



protected void Editar(对象发送者,EventArgs e)

{

使用(GridViewRow row =(GridViewRow)((LinkBut​​ton)sender) .Parent.Parent)

{

txtID.ReadOnly = true;

txtID.Text = row.Cells [0] .Text;

txtUnidadeName.Text = row.Cells [1] .Text;

txtLog radouro.Text = row.Cells [2] .Text;

txtNumero.Text = row.Cells [3] .Text;

txtComplemento.Text = row.Cells [ 4] .Text;

txtBairro.Text = row.Cells [5] .Text;

txtCidade.Text = row.Cells [6] .Text;

txtEstado.Text = row.Cells [7] .Text;

popup.Show();

}

}

protected void保存(对象发送者,EventArgs e)

{

SqlConnection conn = new SqlConnection(strConnString);

conn.Open();



SqlCommand cmd = new SqlCommand(update tb_unidade set NameUnidade = @ NameUnidade,Logradouro = @ Logradouro+

Numero = @ Numero,Complemento = @ Complemento,Bairro = @Bairro,Cidade = @ Cidade,Estado = @ Estado,其中ID = @ID,conn);



cmd.Parameters.AddWithValue(@ NameU nidade,txtUnidadeName.Text);

cmd.Parameters.AddWithValue(@ Logradouro,txtLogradouro.Text);

cmd.Parameters.AddWithValue(@ Numero ,txtNumero.Text);

cmd.Parameters.AddWithValue(@ Complemento,txtComplemento.Text);

cmd.Parameters.AddWithValue(@ Bairro,txtBairro .Text);

cmd.Parameters.AddWithValue(@ Cidade,txtCidade.Text);

cmd.Parameters.AddWithValue(@ Estado,txtEstado.Text );;



cmd.ExecuteNonQuery();

conn.Close();

Response.Write( string.Format(< script> alert('Registro atualizado。');< / script>));



Bind();

}

}

}


</form>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace AgendamentoOnLine
{
public partial class PesquisarUnidade : System.Web.UI.Page
{
private String strConnString = ConfigurationManager.ConnectionStrings["AgendamentoOnLine.Properties.Settings.Setting"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}

protected void Bind()
{
string strQuery = "select ID,UnidadeName,Logradouro,Numero,Complemento,Bairro,Cidade,Estado from tb_unidade";
SqlCommand cmd = new SqlCommand(strQuery);
GridViewUnidade.DataSource = GetData(cmd);
GridViewUnidade.DataBind();
}

private DataTable GetData(SqlCommand cmd)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
}
}

protected void GridViewData_RowCommand(object sender, GridViewCommandEventArgs e)
{

}


protected void Add(object sender, EventArgs e)
{


}

protected void Editar(object sender, EventArgs e)
{
using (GridViewRow row = (GridViewRow)((LinkButton)sender).Parent.Parent)
{
txtID.ReadOnly = true;
txtID.Text = row.Cells[0].Text;
txtUnidadeName.Text = row.Cells[1].Text;
txtLogradouro.Text = row.Cells[2].Text;
txtNumero.Text = row.Cells[3].Text;
txtComplemento.Text = row.Cells[4].Text;
txtBairro.Text = row.Cells[5].Text;
txtCidade.Text = row.Cells[6].Text;
txtEstado.Text = row.Cells[7].Text;
popup.Show();
}
}
protected void Save(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(strConnString);
conn.Open();

SqlCommand cmd = new SqlCommand("update tb_unidade set NameUnidade=@NameUnidade,Logradouro=@Logradouro"+
"Numero=@Numero,Complemento=@Complemento,Bairro=@Bairro,Cidade=@Cidade,Estado=@Estado where ID=@ID", conn);

cmd.Parameters.AddWithValue("@NameUnidade", txtUnidadeName.Text);
cmd.Parameters.AddWithValue("@Logradouro", txtLogradouro.Text);
cmd.Parameters.AddWithValue("@Numero", txtNumero.Text);
cmd.Parameters.AddWithValue("@Complemento", txtComplemento.Text);
cmd.Parameters.AddWithValue("@Bairro", txtBairro.Text);
cmd.Parameters.AddWithValue("@Cidade", txtCidade.Text);
cmd.Parameters.AddWithValue("@Estado", txtEstado.Text);

cmd.ExecuteNonQuery();
conn.Close();
Response.Write(string.Format("<script>alert('Registro atualizado.');</script>"));

Bind();
}
}
}

推荐答案

(#+ elementID).block ({

消息:'
'+

'< img src =imagens / loadingAnim.gif/>
',

css:{ },

overlayCSS:{

backgroundColor:'#000000',不透明度:0.8

}

}) ;

});

prm.add_endRequest(function(){
("#" + elementID).block({
message: '
' +
'<img src="imagens/loadingAnim.gif"/>
',
css: {},
overlayCSS: {
backgroundColor: '#000000', opacity: 0.8
}
});
});
prm.add_endRequest(function () {


(#+ elementID) .unblock();

});

}
("#" + elementID).unblock();
});
}


(document).ready(function(){



BlockUI(<%= pnlAddEdit.ID%>);
(document).ready(function () {

BlockUI("<%=pnlAddEdit.ID %>");


这篇关于Asp.net模态DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆