我正在开发一个系统,当用户在 gridview 中选择一行时,该系统将数据从 jquery-ui 对话框(asp.net 更新面板、搜索数据库和填充 gridview)传递到“主”页面。
一些代码:
JS大师:
$(document).ready(function () {
$('#PesquisaPessoas').dialog({
autoOpen: false,
draggable: false,
modal: true,
title: "Busca de pessoas na Base de Dados",
closeOnEscape: true,
width: 650,
height: 350,
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
});
function showDialog(id) {
$("#" + id).dialog("open");
}
function closeDialog(id) {
$("#" + id).dialog("close");
}
var idCodigo, idNome;
function armazenaIds(cod, nome) {
//stores controls' IDs
idCodigo = cod;
idNome = nome;
}
function preencheTextBoxes(botao) {
//gets fields 0 and 1 (Person's ID and name) from the selected line
var codigo = botao.parent().siblings()[0].textContent;
var nome = botao.parent().siblings()[1].textContent;
$("#"+idCodigo).val(codigo);
$("#"+idNome).val(nome);
$("#CodigoPessoaHiddenField").val(codigo);
}
'主页:
<asp:FormView ID="ContratoFormView" ... et cetera ...>
...
<InsertItemTemplate>
Contratante:
<asp:TextBox ID="PSS_COD_PESSOATextBox" runat="server"
Width="50px"
ReadOnly="True" />
<asp:TextBox ID="PSS_NOMETextBox" runat="server" ReadOnly="True"></asp:TextBox>
<%-- when user clicks the search button, a js function stores the ids of the two textboxes above --%>
<input id="PesquisarButton" type="button"
style="border-style: none; background-image: url('Icons/Search24.png'); background-repeat: no-repeat; background-color: #FFFFFF; width: 24px; height: 24px;"
onclick="showDialog('PesquisaPessoas'); armazenaIds($(this).prev('input').prev('input').attr('id'),$(this).prev('input').attr('id'))" alt="Pesquisar" />
<asp:HiddenField ID="CodigoPessoaHiddenField" runat="server"
ClientIDMode="Static" Value='<%# Bind("PSS_COD_PESSOA") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Cadastrar" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
</InsertItemTemplate>
...
</asp:FormView>
<div id="PesquisaPessoas">
<uc1:PesquisaPessoas ID="PesquisaPessoas1" runat="server" />
</div>
'PesquisaPessoas' 用户控件:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h3>Escolha um dos campos para realizar a busca</h3>
<div align="center">
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Selected="True">Nome</asp:ListItem>
<asp:ListItem>CPF</asp:ListItem>
<asp:ListItem>Data Nascimento</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:TextBox ID="BuscaTextBox" runat="server" AutoPostBack="True"
ontextchanged="BuscaTextBox_TextChanged" Width="250px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="16px"
ImageUrl="~/Icons/Search24.png" onclick="ImageButton1_Click"
Width="16px" />
</div>
<br />
<asp:GridView ID="BuscaPessoaGridView" runat="server"
AutoGenerateColumns="False" DataSourceID="PessoaDataSource"
Visible="False" HorizontalAlign="Center" CssClass="SemBordas" >
<Columns>
<asp:BoundField DataField="PSS_COD_PESSOA" HeaderText="Código"
SortExpression="PSS_COD_PESSOA" />
<asp:BoundField DataField="PSS_NOME" HeaderText="Nome"
SortExpression="PSS_NOME" />
<asp:BoundField DataField="PSS_NUM_CPF" HeaderText="CPF"
SortExpression="PSS_NUM_CPF" />
<asp:BoundField DataField="PSS_DT_NASCIMENTO" DataFormatString="{0:dd/MM/yyyy}"
HeaderText="Data Nasc." SortExpression="PSS_DT_NASCIMENTO" />
<asp:BoundField DataField="PSS_SEXO" HeaderText="Sexo"
SortExpression="PSS_SEXO" />
<asp:BoundField DataField="PSS_NOME_MAE" HeaderText="Nome Mãe"
SortExpression="PSS_NOME_MAE" />
<asp:TemplateField HeaderText="Escolher" ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Select"
ImageUrl="~/Icons/Checkmark.png" Text="OK"
onclientclick="closeDialog('PesquisaPessoas'); preencheTextBoxes($(this)); return false;" />
</ItemTemplate>
<ControlStyle Height="24px" Width="24px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Nenhuma pessoa encontrada. Verifique se os dados foram digitados corretamente.
</EmptyDataTemplate>
</asp:GridView>
<asp:ObjectDataSource ID="PessoaDataSource" runat="server"
SelectMethod="BuscaPessoaPorNome" TypeName="UniVendas.Controle.Fachada.Fachada">
<SelectParameters>
<asp:FormParameter FormField="BuscaTextBox" Name="nome" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
ScriptManager 在页面的其他地方。此代码在 Firefox 和 Chrome 上运行良好(都是最新的)。
在 IE 中,'main' 中的文本框不是由 JS 填充的。