weixin_33743661
weixin_33743661
采纳率0%
2010-11-12 11:56

模态弹出窗口中的Gridview

I wrote a modelpopup which displays a gridview. The gridview loads and the data's are displayed perfectly now i want to select a row and it should pass the values to a couple of textbox which is in the page, from where i opened the popup.

//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 coding

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • csdnceshi58 Didn"t forge 11年前

    Put your text boxes inside an UpdatePanel whose UpdateMode property is set to Always:

    <asp:UpdatePanel ID="upTextBoxes" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        </ContentTemplate>
    </asp:UpdatePanel>
    

    That way, your text boxes will be refreshed when the grid view performs an asynchronous postback.

    EDIT: If you also want to close the modal popup, do that server-side when you update your text boxes:

    protected void gvsearch_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select") {
            TextBox1.Text = e.CommandArgument.ToString();
            mdlPopup.Hide();
        }
    }
    
    点赞 评论 复制链接分享

相关推荐