<asp:GridView ID="grdEmployee" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowDataBound="grdEmployee_RowDataBound"> <Columns> <asp:BoundField DataField="EMP_ID" HeaderText="EMP_ID" /> <asp:BoundField DataField="EMP_NAME" HeaderText="EMP_NAME" /> <asp:BoundField DataField="SALARY" HeaderText="SALARY" /> <asp:BoundField DataField="HIRE_DATE" HeaderText="HIRE_DATE" /> <asp:TemplateField HeaderText="DEPT_ID"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:DropDownList ID="ddlDeptId" runat="server" AutoPostBack="True"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#99CCCC" ForeColor="#003399" /> <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /> <RowStyle BackColor="White" ForeColor="#003399" /> <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> <SortedAscendingCellStyle BackColor="#EDF6F6" /> <SortedAscendingHeaderStyle BackColor="#0D4AC4" /> <SortedDescendingCellStyle BackColor="#D6DFDF" /> <SortedDescendingHeaderStyle BackColor="#002876" /> </asp:GridView>
protected void Bind() { _str = " SELECT EMP_ID,EMP_NAME,SALARY,HIRE_DATE from Employee "; adp = new SqlDataAdapter(_str, con); ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { grdEmployee.DataSource = ds.Tables[0]; grdEmployee.DataBind(); } }
protected void grdEmployee_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.DataRow) { DropDownList ddlDeptId = (DropDownList)e.Row.FindControl("ddlDeptId"); _strdrop = " SELECT distinct Dept_ID from Department "; adpdrp = new SqlDataAdapter(_strdrop, con); dsdrp = new DataSet(); adpdrp.Fill(dsdrp); ddlDeptId.DataSource = dsdrp; ddlDeptId.DataTextField = "Dept_ID"; ddlDeptId.DataValueField = "Dept_ID"; ddlDeptId.ID = "Dept_ID"; ddlDeptId.DataBind(); } } catch (Exception ex) { Response.Write(ex.Message); } }
ddlDeptId.DataSource = ds.Tables[0]; ddlDeptId.DataTextField = "Dept_ID"; ddlDeptId.DataValueField = "Dept_ID"; ddlDeptId.ID = "Dept_ID"; ddlDeptId.DataBind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)