如何将文本框和下拉列表放在Gridview中进行编辑?

时间:2016-11-11 00:16:15

标签: html asp.net vb.net gridview

对不起。我真的很陌生,但我真的很努力。所以我真的需要帮助,如何将文本框和下拉列表放在gridview中进行编辑。

这是我的GridView代码

 <div id="id_tm1" runat="server" class="grid" style="border: 1px solid black; overflow: scroll;
                            width: 94%; height: 103px" visible="true">
                            <asp:GridView ID="gvGroup" runat="server" AllowPaging="true" AllowSorting="True"
                                AutoGenerateColumns="False" BorderColor="Silver" BorderWidth="1px" Height="77px"
                                Width="98%">
                                <RowStyle Font-Names="Arial" Font-Size="9pt" HorizontalAlign="Center" />
                                <Columns>
                                    <asp:BoundField DataField="JOBTITLE" HeaderStyle-BackColor="#666666" HeaderText="Job Title"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">

                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="BUSINESS_UNIT" HeaderStyle-BackColor="#666666" HeaderText="Business Unit"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="DIVISION" HeaderStyle-BackColor="#666666" HeaderText="Division"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="SUB_DIVISION" HeaderStyle-BackColor="#666666" HeaderText="Sub-Division"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="CLASSIFICATION" HeaderStyle-BackColor="#666666" HeaderText="Classification"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="SUB_CLASSIFICATION" HeaderStyle-BackColor="#666666" HeaderText="Sub-Classification"
                                        ItemStyle-Height="10px" ItemStyle-Width="50px">
                                        <HeaderStyle BackColor="#666666" />
                                        <ItemStyle Width="50px" />
                                    </asp:BoundField>
                                </Columns>
                                <PagerStyle Font-Size="9pt" HorizontalAlign="Right" />
                                <EmptyDataTemplate>
                                    <div style="width: 100%; font-size: 10pt; text-align: center; color: Red;">
                                        No record found.
                                    </div>
                                </EmptyDataTemplate>
                                <HeaderStyle BackColor="DarkGray" Font-Bold="True" Font-Names="Arial" Font-Size="9pt"
                                    ForeColor="White" HorizontalAlign="Center" />
                                <AlternatingRowStyle BackColor="Gainsboro" />
                            </asp:GridView>
                        </div>

我尝试将<asp:TemplateField><asp:DropDownList>放在一起,但我遇到了错误&#34; Type&#39; System.Web.UI.WebControls.BoundField&#39;没有名为&#39; TemplateField&#39;的公共财产。或者&#39; DropDownList&#39;

当我单击gridview项目列表中的“编辑”按钮以便能够对其进行编辑时,应显示文本框和下拉列表Output。非常感谢你。

1 个答案:

答案 0 :(得分:0)

在BoundField标记内不允许使用模板字段标记,它应该是标记示例。

<asp:BoundField DataField="JOBTITLE" HeaderStyle-BackColor="#666666"   HeaderText="Job Title"ItemStyle-Height="10px" ItemStyle-Width="50px">
                                    <HeaderStyle BackColor="#666666" />
                                    <ItemStyle Width="50px" />
 </asp:BoundField>

 <asp:TemplateField HeaderText = "Column Header" ItemStyle-Width="95px" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
 <asp:DropDownList ID="yourDrodDown" runat="server">  
         <asp:ListItem Selected="True">Item 1 </asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
       <asp:ListItem>Item 3</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>

</asp:TemplateField>