Aspx page
<asp:TemplateField HeaderStyle-Width="100PX" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
<asp:Label ID="Label3" runat="server" Text="Department"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%#Eval("Department")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" Width="80px" runat="server">
</asp:DropDownList>
<asp:TextBox ID="TextBox5" runat="server" Visible="false" Text='<%#Eval("Department")%>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px"></HeaderStyle>
</asp:TemplateField>
Aspx.cs page
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//string lbl = ((Label)e.Row.FindControl("Label10")).Text;
if (e.Row.RowType == DataControlRowType.DataRow && GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList ddlCities = (DropDownList)e.Row.FindControl("DropDownList4");
TextBox txt = (TextBox)e.Row.FindControl("TextBox5");
string query = "select Dept_Name from DepartmentMaster";
da = new SqlDataAdapter(query, con);
dt = new DataTable();
da.Fill(dt);
ddlCities.DataSource = dt;
ddlCities.DataTextField = "Dept_Name";
ddlCities.DataValueField = "Dept_Name";
ddlCities.DataBind();
ddlCities.Items.Insert(0, txt.Text);
// ddlCities.Items.FindByValue((e.Row.FindControl("lblCity") as Label).Text).Selected = true;
}
}
No comments:
Post a Comment