Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
To Show Team Member With Its Team In Gridview Using Asp.net
WhatsApp
Vandana
Aug 17
2016
812
0
1
<
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();
}
}
Team In Gridview
ASP.NET
Up Next
To Show Team Member With Its Team In Gridview Using Asp.net