ModalPopupExtender文本框未填充子gridview数据

时间:2017-06-10 21:43:31

标签: sql asp.net sql-server vb.net

所以我使用Modal Popup进行gridview编辑。 gridview是另一个gridview的子gridview。我已经将模式弹出窗口移出updatepanel,原因是它在将文本提交到数据库时在文本框的开头添加逗号。在我将模式弹出窗口移出更新面板之前,正在填充文本框,但是现在因为它不再位于具有gridview的更新面板中,所以它不会使用gridview数据填充文本框。有人有什么建议吗?

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>

   <div style="background-color:white;text-align:center; padding:10px;border-radius:15px;box-shadow:5px 10px 15px #303A4C;margin-left:auto;margin-right:auto; max-width:100%;min-width:30%;float:left;">
   <h2 class="h2title">

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" style="float:left;margin-left:10px;">
        <asp:ListItem Value="0">--Select--</asp:ListItem>
        <asp:ListItem Value="1">Options</asp:ListItem>
        <asp:ListItem Value="2">Parts</asp:ListItem>
        <asp:ListItem Value="3">Bid Rates</asp:ListItem>
    </asp:DropDownList>
     Purchasing Approval</h2>

     <asp:Panel ID="panel1" runat="server" Visible="false"  Width="100%">
     <div class="griddiv" style="overflow-y:scroll;max-height:500px; max-width:80%;">

     <asp:GridView ID="GridView1" runat="server" Font-Size="Medium" CellPadding="5" GridLines="None" AutoGenerateColumns="False" 
                        RowStyle-CssClass="rows" HeaderStyle-CssClass="gridheader" DataKeyNames="batchID" OnRowDataBound="OnRowDataBound" >

                            <Columns>
                               <asp:TemplateField>
                                <ItemTemplate>
                                    <img alt = "" style="cursor: pointer" src="../img/plus.png" />
                                    <asp:Panel ID="childpanel" runat="server" Style="display: none;">
                                    <div class="griddiv" style="overflow-y:scroll;max-height:500px; max-width:80%;">
                                        <asp:GridView ID="gvchild" runat="server" Font-Size="Medium" CellPadding="5" GridLines="None" AutoGenerateColumns="False" 
                                                        CssClass="datagrid1" RowStyle-CssClass="rows" HeaderStyle-CssClass="gridheader" DataKeyNames="id">
                                            <Columns>
                                            <asp:TemplateField ItemStyle-Width = "30px" HeaderText = "">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lnkEdit" runat="server" Text = "Edit" OnClick = "Edit"></asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                             <asp:TemplateField HeaderText="Option Number">  
                                                <ItemTemplate>  
                                                        <asp:Label ID="optionnumtemp" runat="server" Text='<%#Eval("optionnum") %>'></asp:Label>  
                                                    </ItemTemplate>  
                                                </asp:TemplateField>  
                                                <asp:BoundField ItemStyle-Width="150px" DataField="id" HeaderText="ID" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="optionnum" HeaderText="Option Number" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="optiondesc" HeaderText="Option Description" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="optioncat" HeaderText="Option Category" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="houseplan" HeaderText="House Plan" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="craftcode" HeaderText="Craft Code" />
                                                <asp:BoundField ItemStyle-Width="150px" DataField="parentoption" HeaderText="Parent Option" />
                                                <asp:TemplateField>
                                                <HeaderTemplate>
                                                        <asp:CheckBox runat="server" ID="chkHeader" TextAlign="Right"/>
                                                </HeaderTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:CheckBox runat="server" ID="chkRow"/>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>
                                        </div>

                                    </asp:Panel>

                                </ItemTemplate>
                            </asp:TemplateField>
                                <asp:BoundField DataField = "batchID" HeaderText = "Batch ID" HtmlEncode = "true" HeaderStyle-Width="25%" />
                                <asp:BoundField DataField = "requestdate" HeaderText = "Request Date" HtmlEncode = "true" HeaderStyle-Width="25%" />
                                <asp:BoundField DataField = "requestby" HeaderText = "Requested By" HtmlEncode = "true" HeaderStyle-Width="25%"/>
                                <asp:BoundField DataField = "entityname" HeaderText = "Division" HtmlEncode = "true" HeaderStyle-Width="25%"/>

                            </Columns>

                        </asp:GridView>
                         <div class="button">
                                             <asp:Button ID="Button" runat="server" Text="Complete" />
                                       </div>
                        </div>
                        </asp:Panel>
</ContentTemplate>
         <Triggers>
            <asp:AsyncPostBackTrigger ControlID = "GridView1" />
            <asp:AsyncPostBackTrigger ControlID = "btnSave" />
          </Triggers>
         </asp:UpdatePanel>
         <asp:Panel ID="pnlAddEdit" runat="server" CssClass="modalPopup" style = "display:none">
                                <asp:Label Font-Bold = "true" ID = "Label4" runat = "server" Text = "Option Request" ></asp:Label>
                                <br />
                                <table align = "center">
                                <tr>
                                <td>
                                <asp:Label ID="rowid" runat="server" Text = "ID"></asp:Label>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label1" runat = "server" Text = "Option Number" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="optionnumtxt" runat="server"></asp:TextBox>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label2" runat = "server" Text = "Option Description" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="optiondesctxt" runat="server"></asp:TextBox>   
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label3" runat = "server" Text = "Option Category" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="optcattxt" runat="server"></asp:TextBox>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label5" runat = "server" Text = "House Plan" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="houseplantxt" runat="server"></asp:TextBox>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label6" runat = "server" Text = "Craft Code" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="craftcodetxt" runat="server"></asp:TextBox>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Label ID = "Label7" runat = "server" Text = "Parent Option" ></asp:Label>
                                </td>
                                <td>
                                <asp:TextBox ID="parentoptiontxt" runat="server"></asp:TextBox>
                                </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:Button ID="btnSave" runat="server" Text="Save" OnClick = "Save" />
                                </td>
                                <td>
                                <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick = "return Hidepopup()"/>
                                </td>
                                </tr>
                                </table>
                                </asp:Panel>
                               <asp:LinkButton ID="lnkFake" runat="server"></asp:LinkButton>
                                <ajax:ModalPopupExtender ID="popup" runat="server" DropShadow="false"
                                    PopupControlID="pnlAddEdit" TargetControlID = "lnkFake"
                                    BackgroundCssClass="modalBackground">
                                </ajax:ModalPopupExtender>

受保护的子编辑(ByVal sender As Object,ByVal e As EventArgs)

For Each gvrow As GridViewRow In GridView1.Rows
    Dim gvchild As GridView = TryCast(gvrow.FindControl("gvchild"), GridView)
    Dim row As GridViewRow = CType(CType(sender, LinkButton).Parent.Parent, GridViewRow)

    rowid.Text = row.Cells(1).Text
    optionnumtxt.Text = row.Cells(2).Text
    optiondesctxt.Text = row.Cells(3).Text
    optcattxt.Text = row.Cells(4).Text
    houseplantxt.Text = row.Cells(5).Text
    craftcodetxt.Text = row.Cells(6).Text
    parentoptiontxt.Text = row.Cells(7).Text
    popup.Show()

Next

End Sub

1 个答案:

答案 0 :(得分:0)

经过一段时间没有回应,我试图弄清楚这对我的环境有用。

parentoption = parentoption.Split(",").Last()

这将删除逗号和逗号前面的任何内容,以便提交的唯一文本是输入的新文本。