努力打造编程资料第一站
你现在所在的位置:主页 > 开发 > .Net >

DetailsView使用DropDownList

来自: 未知   |  作者:冰河  |   时间:2010-06-09 10:12

摘要:在DetailsView中创建一个模板列,在模板列中加入DropDownList 例: asp:TemplateField HeaderText=类型 EditItemTemplate asp:DropDownList ID=DropDownList2 runat=server asp:ListItem0/asp:ListItem asp:ListItem1/asp:ListItem asp:ListItem2/asp:

在DetailsView中创建一个模板列,在模板列中加入DropDownList
例:

<asp:TemplateField HeaderText="类型">
   <EditItemTemplate>
       <asp:DropDownList ID="DropDownList2" runat="server">
       <asp:ListItem>0</asp:ListItem>
       <asp:ListItem>1</asp:ListItem>
       <asp:ListItem>2</asp:ListItem>
       <asp:ListItem>3</asp:ListItem>
       </asp:DropDownList>
   </EditItemTemplate>
   <InsertItemTemplate>
       <asp:DropDownList ID="DropDownList1" runat="server">
       <asp:ListItem>00</asp:ListItem>
       <asp:ListItem>11</asp:ListItem>


       <asp:ListItem>22</asp:ListItem>
       <asp:ListItem>33</asp:ListItem>
       </asp:DropDownList>
    </InsertItemTemplate>
</asp:TemplateField>

在插入(DetailsView1_ItemInserting)或更新(DetailsView1_ItemUpdating)事件中加入
代码:
     string str=((DropDownList)DetailsView1.Rows[3].Cells[1].FindControl("DropDownList1")).SelectedValue
 e.Values.Add("type", str);
 
就这样就可以使用DropDownList  或其它控件了.

 

 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码: 点击我更换图片
站内推荐
行业热点
论坛新帖