C# 在gridview行文本框中获取模式弹出值

C# 在gridview行文本框中获取模式弹出值,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个带有动态控件的gridview。资源名称是我从Active directory获取的内容。搜索过滤器的工作方式是,您必须输入lastname、firstname并单击它将搜索的查找。如果有多条记录,modalpopup将显示dropdownlist,其中包含可供选择的选项 问题是我无法将下拉值填充到gridview中的文本框中。我需要在正确选定行的文本框中输入此下拉值。 代码隐藏: protected void gvProjectResource_RowCommand(object

我有一个带有动态控件的gridview。资源名称是我从Active directory获取的内容。搜索过滤器的工作方式是,您必须输入lastname、firstname并单击它将搜索的查找。如果有多条记录,modalpopup将显示dropdownlist,其中包含可供选择的选项

问题是我无法将下拉值填充到gridview中的文本框中。我需要在正确选定行的文本框中输入此下拉值。

代码隐藏:

protected void gvProjectResource_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Lookup")
        {
            GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
            TextBox t2 = ((TextBox)clickedRow.FindControl("t2"));

            DataTable dt = globalObj.FindPersons(t2.Text.Split(',')[0].Trim(), t2.Text.Split(',')[1].Trim());
            if (dt.Rows.Count > 1)
            {
                mpFindPerson.Show();
                ddlPersons.Items.Clear();
                ddlPersons.Items.Add(new ListItem { Value = "0", Text = "-Select User-" });
                ddlPersons.DataSource = dt;
                dt.Columns.Add("FullName", typeof(string), "DisplayName + ' | ' + MSID");
                ddlPersons.DataTextField = "FullName";
                ddlPersons.DataValueField = "MSID";
                ddlPersons.DataBind(); 
            }
            else
            {
                t2.Text = dt.Rows[0].ItemArray[0].ToString(); 
            }
        }
        if (e.CommandName == "Del")
        { 

        }
    } 

protected void btnSelectPerson_Click(object sender, EventArgs e)
    {
        TextBox t2 = (gvProjectResource.SelectedRow.FindControl("t2") as TextBox);
        t2.Text = ddlPersons.SelectedItem.Text;
        mpFindPerson.Hide();
    }
ASPX代码:

<div id="four">
                    <fieldset style="border: solid; border-width: thin; height: 220px; border-color: #a8a8a8;">
                        <legend id="Legend11" runat="server" visible="true" style="width: auto; margin-bottom: 0px; font-size: 12px; font-weight: bold; color: #1f497d;">&nbsp;&nbsp; Project Resources &nbsp;&nbsp;</legend>
                        <div style="height: 210px; overflow: auto;">
                            <asp:GridView ID="gvProjectResource" Width="88%" HeaderStyle-Font-Size="X-Small" CssClass="labels" runat="server" 
                                ShowFooter="true" AutoGenerateColumns="false" Style="margin-right: auto; margin-left:7px;"
                                OnRowDataBound="gvProjectResource_RowDataBound"
                                OnRowCommand="gvProjectResource_RowCommand" >
                                <Columns>
                                    <asp:TemplateField HeaderText="Role" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
                                        <ItemTemplate>
                                            <asp:Label ID="lblRole" runat="server" Text='<%# Eval("role") %>' Visible="false" />
                                            <asp:DropDownList ID="ddlRole" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="ddlRole2" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
                                        </FooterTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Resource Name" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
                                        <ItemTemplate>
                                            <asp:TextBox ID="t1" Height="23px" Width="98%" runat="server" ></asp:TextBox>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:TextBox ID="t2" Height="23px" Width="68%" runat="server"></asp:TextBox>
                                            <asp:LinkButton runat="server" Text="Lookup" CommandName="Lookup" />
                                        </FooterTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField ItemStyle-VerticalAlign="Top" ItemStyle-Width="5%">
                                        <ItemTemplate>
                                            <asp:LinkButton runat="server" Text="Delete" CommandName="Del" />
                                        </ItemTemplate> 
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <br />
                            <div style="text-align: right;">
                                <asp:LinkButton runat="server" Text="Add New" ID="LinkButton2" CssClass="labels"></asp:LinkButton>
                            </div>
                        </div>

                        <asp:Button runat="server" ID="btnModalPopUpSearch" Style="display: none" />
                        <AjaxToolkit:ModalPopupExtender ID="mpFindPerson"
                            BehaviorID="mpFindPersonBehav"
                            runat="server"
                            DropShadow="true"
                            BackgroundCssClass="modalBackground"
                            PopupControlID="pnlFindPerson"
                            TargetControlID="btnModalPopUpSearch">
                        </AjaxToolkit:ModalPopupExtender>
                        <asp:Panel runat="Server" ID="pnlFindPerson" CssClass="modalPopup" style="position:relative;">
                            <div class="labels" runat="server" style="text-align:center; position:absolute; top:20%; height:10em; margin-top:auto; margin-left:20px;">
                                <asp:DropDownList ID="ddlPersons" runat="server" AppendDataBoundItems="true" Width="200px">
                                    <asp:ListItem Text="-Select User-" Value="0" />
                                </asp:DropDownList>
                                <br />
                                <br />
                                <br />
                                <div style="text-align: center;">
                                    <asp:Button runat="server" Font-Size="9pt" Text="Select" CssClass="buttons___" Style="float: left;"
                                        ID="btnSelectPerson" OnClick="btnSelectPerson_Click" />
                                </div>
                            </div>
                        </asp:Panel>

                    </fieldset>
                </div> 

项目资源





好的,所以没什么事可做

我必须加上这个

protected void btnSelectPerson_Click(object sender, EventArgs e)
    { 
        TextBox t2 = (TextBox)gvProjectResource.FooterRow.FindControl("t2");
        t2.Text = ddlPersons.SelectedItem.Text;

        mpFindPerson.Hide();
    }