How to bind dropdown in Gridview throgh code behnd dynmclly?
How to bind dropdown in Gridview through code behind while user clicks on gridview
Edit link?
I am showing dropdown when user clicks on Edit link.
want to load dropdown dynamically.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [employee] WHERE [id] = @id" InsertCommand="INSERT INTO [employee] ([name], [age], [dept],
[location], [salary]) VALUES (@name, @age, @dept, @location, @salary)" SelectCommand="SELECT [name], [age], [dept], [location], [salary],
[id] FROM [employee]" UpdateCommand="UPDATE
[employee] SET [name] = @name, [age] = @age, [dept] = @dept, [location] =
@location, [salary] = @salary WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="age" Type="Int32" />
<asp:Parameter Name="dept" Type="String" />
<asp:Parameter Name="location" Type="String" />
<asp:Parameter Name="salary" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="age" Type="Int32" />
<asp:Parameter Name="dept" Type="String" />
<asp:Parameter Name="location" Type="String" />
<asp:Parameter Name="salary" Type="Int32" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" >
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:TemplateField HeaderText="dept" SortExpression="dept">
<EditItemTemplate>
<asp:DropDownList ID="drpDownList2" runat="server" >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("dept") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="location" HeaderText="location" ortExpression="location" />
<asp:BoundField DataField="salary" HeaderText="salary" SortExpression="salary" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
</div>
</form>
</body>
</html>