In this post, i will tell you about Showing Team Member With Its Team In Gridview Using ASP.NET. This following code snippet is for to show team member with its team in Gridview using ASP.NET:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"> 
    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> 
    <HeaderStyle BackColor="#990000" Font-Bold="true" ForeColor="#FFFFCC" /> 
    <AlternatingRowStyle BackColor="#DFDFD0" /> 
    <Columns> 
        <asp:BoundField DataField="Teamname" HeaderText="Teamname" /> 
        <asp:TemplateField HeaderText="Agentname"> 
            <ItemTemplate> 
                <asp:DropDownList ID="ddlagent" runat="server" Width="250px" /> </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="CountAgent"> 
            <ItemTemplate> 
                <asp:Label ID="lblAgent" runat="server" Width="100px" /> </ItemTemplate> 
        </asp:TemplateField> 
    </Columns> 
    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> 
    <RowStyle BackColor="White" ForeColor="#330099" /> 
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" /> 
    <SortedAscendingCellStyle BackColor="#FEFCEB" /> 
    <SortedAscendingHeaderStyle BackColor="#AF0101" /> 
    <SortedDescendingCellStyle BackColor="#F6F0C0" /> 
    <SortedDescendingHeaderStyle BackColor="#7E0000" />  
</asp:GridView> 

Code

using System.Data; 
using System.Data.SqlClient; 
using System.Configuration; 
public partial class Default2: System.Web.UI.Page { 
    string ConnStr = ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString(); 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CRMConnectionString"].ToString()); 
    DataSet someDataSet = new DataSet(); 
    SqlDataAdapter adapt = new SqlDataAdapter(); 
    protected void Page_Load(object sender, EventArgs e) { 
        TopTeam(); 
    } 
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { 
        if (e.Row.RowType == DataControlRowType.DataRow) { 
            con.Open(); 
            var ddl = (DropDownList) e.Row.FindControl("ddlagent"); 
            var Agent = (Label) e.Row.FindControl("lblAgent"); 
            string TeamName = e.Row.Cells[0].Text.ToString(); 
            SqlCommand cmd = new SqlCommand("SELECT distinct (Agentname +' , ' + Hr_id) as [Agentname] FROM CRM_Agentname " + " WHERE TeamName = '" + TeamName + "' and status='Active'", con); 
            SqlDataAdapter da = new SqlDataAdapter(cmd); 
            DataSet ds = new DataSet(); 
            da.Fill(ds); 
            con.Close(); 
            ddl.DataSource = ds; 
            ddl.DataTextField = "Agentname"; 
            ddl.DataValueField = "Agentname"; 
            ddl.DataBind(); 
            int totalItems = ddl.Items.Count; 
            Agent.Text = totalItems.ToString(); 
        } 
    } 
    private void TopTeam() { 
        con.Open(); 
        SqlCommand cmd = new SqlCommand("SELECT DISTINCT TeamName FROM CRM_Teamname where status='ACtive' and process like 'r%' and teamname!='---- Select ----'", con); 
        SqlDataAdapter da = new SqlDataAdapter(cmd); 
        DataSet ds = new DataSet(); 
        da.Fill(ds); 
        con.Close(); 
        GridView1.DataSource = ds; 
        GridView1.DataBind(); 
        con.Close(); 
    } 
}

HostForLIFE.eu ASP.NET Core 1.0 Hosting

European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.