Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
<%@ 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="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>


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();
}
}
}
Posted
Updated 13-Nov-15 12:54pm
v2
Comments
Where is your question?
Member 12107877 14-Nov-15 9:54am    
My question and it does not do the update, he turns pro Modaul and not updated and I do not know what's wrong.
You should debug and find out the issue then. Also log exceptions by putting try catch blocks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900