2017-04-17 71 views
0

我有一个带有动态控件的gridview。资源名称是我从Active Directory中选取的东西。搜索过滤器的工作方式是,您必须输入姓氏,名字和搜索字词,然后搜索。如果有多个记录,则会显示一个modalpopup,并在下拉列表中显示可供选择的选项。在gridview行文本框中获取模态弹出窗口值

enter image description here

enter image description here

的问题是,我无法得到填充到文本框出现在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> 

回答

0

行,所以,没有什么太多的事情。

必须添加此。

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

     mpFindPerson.Hide(); 
    } 
相关问题