Click here to Skip to main content
15,917,456 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How to add a dropdown field in a Gridview?
Posted
Updated 31-Mar-11 10:59am
v2

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.
 
Share this answer
 
Create a ItemTemplate in GridView. And Place DropDown inside your ItemTemplate.

If DropDown Items are dynamic add datasource to bind the DropDown.
 
Share this answer
 
Use this code I think this will give you complete solution.


XML
<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>








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
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900