我写了一个模型弹出窗口,显示一个网格视图。网格视图已经加载并且数据已经完美地显示出来了,现在我想选择一行,并将它的值传递给打开弹出窗口的页面上的几个文本框。
//default.aspx
//default.aspx
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
EnableScriptLocalization="true">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="btnclear" runat="server" CssClass="LPS_Button" Text="Clear" OnClick="btnclear_Click" />
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<cc1:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlCities" CancelControlID="btnClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlCities" runat="server" Style="background-color: White; border-color: Black;
border-style: solid; border-width: thin;" SkinID="PopUpPanel">
<asp:UpdatePanel ID="upCities" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblCities" runat="server" Text="Search Result" SkinID="Heading"></asp:Label><br />
<asp:GridView ID="gvsearch" CssClass="LPS_DataGrid" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" GridLines="None" Height="100%" OnPageIndexChanging="gvsearch_PageIndexChanging"
PageSize="5" ShowFooter="True" Width="100%" OnRowCommand="gvsearch_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:HyperLink ID="lnkid" runat="server" Text='<%# Bind("ID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="lnkname" runat="server" Text='<%# Bind("Name") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:Button ID="btgselect" runat="server" Text="Select" CommandName="Select" CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle />
<FooterStyle CssClass="LPS_Grid_FooterStyle" />
<PagerStyle CssClass="LPS_Grid_PageStyle" />
<SelectedRowStyle CssClass="LPS_Grid_SelectedRowStyle" />
<HeaderStyle CssClass="LPS_Grid_HeaderStyle" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<div style="text-align: center; width: 100%; margin-top: 5px;">
<asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
</div>
</asp:Panel>
</asp:Content>
// default.aspx.cs 代码
protected void btnclear_Click(object sender, EventArgs e)
{
popup();
//Session["tablename"] = "Vendor";
//Response.Write("<script language='javascript'>window.open('Search.aspx',null,'height=450, width=450,status= no, resizable= no, scrollbars=yes, toolbar=no,location=no,menubar=no ');</script>");
}
protected void gvsearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
popup();
gvsearch.PageIndex = e.NewPageIndex;
gvsearch.DataBind();
}
void popup()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
popupsearch pop = new popupsearch();
XmlDocument xmlsearch = new XmlDocument();
XmlElement xmlroot = xmlsearch.CreateElement("Search");
XmlElement xmlsearchs = xmlsearch.CreateElement("Popup");
xmlsearchs.SetAttribute("tablename", "employee");
xmlroot.AppendChild(xmlsearchs);
xmlsearch.AppendChild(xmlroot);
ds = pop.search(xmlsearch);
dt = ds.Tables.Add("list");
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Name", Type.GetType("System.String"));
DataRow myRow;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows.Count > 0)
{
myRow = dt.NewRow();
myRow["ID"] = ds.Tables[0].Rows[i][0].ToString();
myRow["Name"] = ds.Tables[0].Rows[i][1].ToString();
dt.Rows.Add(myRow);
}
}
gvsearch.DataSource = ds.Tables["list"];
gvsearch.DataBind();
upCities.Update();
mdlPopup.Show();
}
protected void gvsearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
TextBox1.Text = e.CommandArgument.ToString();
}
}
please friends help me.