<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Employee_Mangment.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" OnRowDeleted="GridView1_RowDeleted" DataKeyNames="ID" OnRowUpdated="GridView1_RowUpdated" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ReadOnly="true" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:TemplateField HeaderText="Education" SortExpression="Education"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource2" DataTextField="EducationType" DataValueField="EducationType" SelectedValue='<%# Bind("Education") %>'> </asp:DropDownList> <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetEducations" TypeName="Employee_Mangment.Data.EducationDataAccess"></asp:ObjectDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Education") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Label ID="Label1" runat="server" Text="" Font-Bold="true"></asp:Label> <asp:Label ID="Label2" runat="server" Text="" Font-Bold="true"></asp:Label> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetEmployees" TypeName="Employee_Mangment.Data.EmployeeDataAccess" UpdateMethod="UpdateEmployee" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="Original_{0}" DeleteMethod="DeleteEmployee" OnDeleted="ObjectDataSource1_Deleted" OnUpdated="ObjectDataSource1_Updated"> <DeleteParameters> <asp:Parameter Name="Original_ID" Type="Int32" /> <asp:Parameter Name="Original_Name" Type="String" /> <asp:Parameter Name="Original_Education" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Original_ID" Type="Int32" /> <asp:Parameter Name="Original_Name" Type="String" /> <asp:Parameter Name="Original_Education" Type="String" /> <asp:Parameter Name="Name" Type="String" /> <asp:Parameter Name="Education" Type="String" /> </UpdateParameters> </asp:ObjectDataSource> </div> </form> </body> </html>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { DropDownList drop = (DropDownList)GridView1.Rows[1].FindControl("DropDownList1"); } }
GridView1_RowDataBound()
GridView1.Rows[1]
GridView1_RowDataBound
DropDownList drop = (DropDownList)e.Row.FindControl("DropDownList1");
EditItemTemplate
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) != 0) { DropDownList drop = (DropDownList)e.Row.FindControl("DropDownList1"); ... } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)