Thursday, September 16, 2010

How to bind data to DropDownList in GridView in ASP.Net and C#

 How to bind data to DropDownList in GridView in ASP.Net and C#  
 In this article i am explaining how to bind data to DropDownList inside asp.net GridView control.  
 protected void GridDegree_RowDataBound(object sender, GridViewRowEventArgs e)  
 {  
      if (e.Row.RowType == DataControlRowType.DataRow)  
      {   
           DropDownList ddlDegreeType = (DropDownList)e.Row.FindControl("ddlDegreeType");  
           if (ddlDegreeType != null)  
           {  
                ddlDegreeType.DataSource = objDegreeDAL.GetDegree();   
                ddlDegreeType.DataBind();  
                ddlDegreeType.SelectedValue = dsDegree.Tables[0].Rows[e.Row.RowIndex]["DegreeId"].ToString();  
           }  
      }  
 }  
 .aspx page   
 <asp:TemplateField HeaderText="Degree Type>  
      <ItemTemplategt>  
           <asp:Label ID="lblDegreeType" runat="server" Text='<%# Bind("[Degree]") %></asp:Label>  
      </ItemTemplategt>  
      <EditItemTemplate>  
      <asp:DropDownList ID="ddlDegreeType" runat="server" DataTextField="Degree"  
      DataValueField="Degreeid>  
      </asp:DropDownList>  
      </EditItemTemplate>  
 </asp:TemplateField>  

1 comment:

  1. Excellent blog since I have visited is really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative. We are also providing the best services click on below links to visit our website.
    Oracle Fusion HCM Training
    Workday Training
    Okta Training
    Palo Alto Training
    Adobe Analytics Training

    ReplyDelete