如何在Gridview中添加下拉字段? [英] How to add a dropdown field in a Gridview?

查看:91
本文介绍了如何在Gridview中添加下拉字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Gridview中添加下拉字段?

How to add a dropdown field in a Gridview?

推荐答案

在这里:
访问GridView中的DropDownList [ GridView内部的DropDownList(方法1) [在ASP.NET 2.0(C#)中将DropDownList嵌套到Gridview [ ^ ]

下次,请使用Google-效果很好.此外,也要花一些时间来阐述问题.
Here you go:
Accessing a DropDownList inside a GridView[^]
DropDownList Inside GridView (Method 1) [^]
Nesting the DropDownList to Gridview in ASP.NET 2.0(C#)[^]

Next time, please use Google - it works wonder. Further, do spend some time in formulating the question too.


在GridView中创建一个ItemTemplate.并将DropDown放入您的ItemTemplate中.

如果DropDown Items是动态的,请添加数据源以绑定DropDown.
Create a ItemTemplate in GridView. And Place DropDown inside your ItemTemplate.

If DropDown Items are dynamic add datasource to bind the DropDown.


使用此代码,我认为这将为您提供完整的解决方案.


Use this code I think this will give you complete solution.


<asp:GridView id="grdSystemInfo" runat="server" Width="940px"

                       Font-Names="Verdana" Font-Size="Small" UseAccessibleHeader="False"  PageSize="5"

                       AllowPaging="True" OnPageIndexChanging="grdSystemInfo_PageIndexChanging" onrowcommand="grdSystemInfo_RowCommand"

                       >
           <PagerStyle Font-Bold="True"  />
           <HeaderStyle Font-Names="Verdana" Font-Size="Small" Font-Bold="True" BackColor="#E0E0E0"  />
           <Columns>
           <asp:BoundField DataField="DateTimes"  HeaderText="DateAccessed" />
           <asp:TemplateField HeaderText="Search By">
           <ItemTemplate>
               <asp:DropDownList ID="DropDownList2" runat="server"  OnSelectedIndexChanged="drpl2_selectedIndexChange" AutoPostBack="true">
               <asp:ListItem>Monitor Details</asp:ListItem>
               <asp:ListItem>KeyBoard Details</asp:ListItem>
               <asp:ListItem>Mouse Details</asp:ListItem>
               <asp:ListItem>Processor Details</asp:ListItem>
               <asp:ListItem>O/S Details</asp:ListItem>
               <asp:ListItem>HardDisk Details</asp:ListItem>
               </asp:DropDownList>
           </ItemTemplate>
           </asp:TemplateField>
           </Columns>
       </asp:GridView>









受保护的void drpl2_selectedIndexChange(对象发送者,EventArgs e)
{
//获取对行的引用
GridViewRow gvr =(GridViewRow)((((Control)sender).NamingContainer);
//获取此DropDownlist的引用
DropDownList ddlItem =(DropDownList)gvr.FindControl("DropDownList2");
//在这里进行处理
}









protected void drpl2_selectedIndexChange(object sender, EventArgs e)
{
// get reference to the row
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer);
// Get the reference of this DropDownlist
DropDownList ddlItem = (DropDownList)gvr.FindControl("DropDownList2");
//do the processing here
}


这篇关于如何在Gridview中添加下拉字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆