Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

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>  

No comments:

Post a Comment