Jim2Yoo

导航

在asp.net 2.0的detailview中使用dropdownlist控件

 <asp:TemplateField HeaderText="priority" SortExpression="priority">
                                    
<EditItemTemplate>
                                        
<asp:DropDownList ID="DropDownList3" runat="server">
                                            
<asp:ListItem Value="4">AA</asp:ListItem>
                                            
<asp:ListItem Value="3">A</asp:ListItem>
                                            
<asp:ListItem Value="2">B</asp:ListItem>
                                            
<asp:ListItem Value="1">C</asp:ListItem>
                                        
</asp:DropDownList>
                                    
</EditItemTemplate>
                                    
<InsertItemTemplate>
                                        
<asp:DropDownList ID="DropDownList3" runat="server" SelectedValue='<%# Bind("priority") %>'>
                                            
<asp:ListItem Value="4">AA</asp:ListItem>
                                            
<asp:ListItem Value="3">A</asp:ListItem>
                                            
<asp:ListItem Value="2">B</asp:ListItem>
                                            
<asp:ListItem Value="1">C</asp:ListItem>
                                        
</asp:DropDownList>
                                    
</InsertItemTemplate>
                                    
<ItemTemplate>
                                        
<asp:Label ID="Label2" runat="server" Text='<%# Bind("priority") %>'></asp:Label>
                                    
</ItemTemplate>
                                
</asp:TemplateField>

对于detailview,我们可以实现view,update,insert,如果不用模版,默认是按照数据类型来生成update和insert时候的用户界面,一般就是text和checkbox,如果我们需要使用dropdownlist,那就要自己编辑里面的模版,典型代码都在上面,这里不罗唆了,有一个地方要注意,就是<asp:DropDownList ID="DropDownList3" runat="server" SelectedValue='<%# Bind("priority") %>'>这一行中的SelectedValue='<%# Bind("priority") %>'
如果不写,那么提交的时候这个控件的值是不会保存的,具体原因我也不知道,查了半天国外的网站找到的。这里贴出来给有同样问题的朋友共享。

posted on 2006-07-26 17:22  Jimmy.Yu  阅读(759)  评论(0编辑  收藏  举报