To Show Team Member With Its Team In Gridview Using Asp.net

  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4">  
  2.     <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />  
  3.     <HeaderStyle BackColor="#990000" Font-Bold="true" ForeColor="#FFFFCC" />  
  4.     <AlternatingRowStyle BackColor="#DFDFD0" />  
  5.     <Columns>  
  6.         <asp:BoundField DataField="Teamname" HeaderText="Teamname" />  
  7.         <asp:TemplateField HeaderText="Agentname">  
  8.             <ItemTemplate>  
  9.                 <asp:DropDownList ID="ddlagent" runat="server" Width="250px" /> </ItemTemplate>  
  10.         </asp:TemplateField>  
  11.         <asp:TemplateField HeaderText="CountAgent">  
  12.             <ItemTemplate>  
  13.                 <asp:Label ID="lblAgent" runat="server" Width="100px" /> </ItemTemplate>  
  14.         </asp:TemplateField>  
  15.     </Columns>  
  16.     <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />  
  17.     <RowStyle BackColor="White" ForeColor="#330099" />  
  18.     <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />  
  19.     <SortedAscendingCellStyle BackColor="#FEFCEB" />  
  20.     <SortedAscendingHeaderStyle BackColor="#AF0101" />  
  21.     <SortedDescendingCellStyle BackColor="#F6F0C0" />  
  22.     <SortedDescendingHeaderStyle BackColor="#7E0000" />   
  23. </asp:GridView>  
Code
  1. using System.Data;  
  2. using System.Data.SqlClient;  
  3. using System.Configuration;  
  4. public partial class Default2: System.Web.UI.Page {  
  5.     string ConnStr = ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString();  
  6.     SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString());  
  7.     DataSet someDataSet = new DataSet();  
  8.     SqlDataAdapter adapt = new SqlDataAdapter();  
  9.     protected void Page_Load(object sender, EventArgs e) {  
  10.         TopTeam();  
  11.     }  
  12.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {  
  13.         if (e.Row.RowType == DataControlRowType.DataRow) {  
  14.             con.Open();  
  15.             var ddl = (DropDownList) e.Row.FindControl("ddlagent");  
  16.             var Agent = (Label) e.Row.FindControl("lblAgent");  
  17.             string TeamName = e.Row.Cells[0].Text.ToString();  
  18.             SqlCommand cmd = new SqlCommand("SELECT distinct (Agentname +' , ' + Hr_id) as [Agentname] FROM CRM_Agentname " + " WHERE TeamName = '" + TeamName + "' and status='Active'", con);  
  19.             SqlDataAdapter da = new SqlDataAdapter(cmd);  
  20.             DataSet ds = new DataSet();  
  21.             da.Fill(ds);  
  22.             con.Close();  
  23.             ddl.DataSource = ds;  
  24.             ddl.DataTextField = "Agentname";  
  25.             ddl.DataValueField = "Agentname";  
  26.             ddl.DataBind();  
  27.             int totalItems = ddl.Items.Count;  
  28.             Agent.Text = totalItems.ToString();  
  29.         }  
  30.     }  
  31.     private void TopTeam() {  
  32.         con.Open();  
  33.         SqlCommand cmd = new SqlCommand("SELECT DISTINCT TeamName FROM CRM_Teamname where status='ACtive' and process like 'r%' and teamname!='---- Select ----'", con);  
  34.         SqlDataAdapter da = new SqlDataAdapter(cmd);  
  35.         DataSet ds = new DataSet();  
  36.         da.Fill(ds);  
  37.         con.Close();  
  38.         GridView1.DataSource = ds;  
  39.         GridView1.DataBind();  
  40.         con.Close();  
  41.     }  
  42. }