0% found this document useful (0 votes)
16 views

code with check box in every line

The document is a C# code snippet for a web user control that manages a roadmap experience and product mapping in a SharePoint environment. It includes methods for loading user data, filtering experiences, binding data to a grid, and handling checkbox selections. The code also implements data grouping and dynamic column creation based on experience levels and tech concepts.

Uploaded by

girraj gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

code with check box in every line

The document is a C# code snippet for a web user control that manages a roadmap experience and product mapping in a SharePoint environment. It includes methods for loading user data, filtering experiences, binding data to a grid, and handling checkbox selections. The code also implements data grouping and dynamic column creation based on experience levels and tech concepts.

Uploaded by

girraj gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

using System;

using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections;
using Newtonsoft.Json;

namespace NTD.VWP.NTD_SC_RoadmapExpSMLwiseproductMapping
{
public partial class NTD_SC_RoadmapExpSMLwiseproductMappingUserControl :
PageBase
{
string UserID = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

UserID = Username();
UserLog(UserID);
FillListAll("All", ddlFilterExperience,
GetDataTable("ntd_SC_GetFilterEXperiance"), "Name", "ID");
BindGrid(null);

FillListForMultiSelect("All", ddlproduct,
GetDataTable("SP_NTD_NM_GetProductList", "Flag,UserID,ProductID,ModelID", 4,
UserID, "", ""), "Product_Name", "ProductI_ID");

}
}

protected void CheckAll_CheckedChanged(object senderr, EventArgs e)


{
CheckBox headerCheckBox = (CheckBox)senderr;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox itemCheckBox = (CheckBox)row.FindControl("ItemCheckBox");
if (itemCheckBox != null)
{
itemCheckBox.Checked = headerCheckBox.Checked;
}
}
}
private void BindGrid(string experienceFilter)
{
// Fetch data from the database
DataTable dt = GetDataTable("ntd_SC_GetRoadmapExpSMLwiseproduct");

// If an experience filter is provided, apply it


if (!string.IsNullOrEmpty(experienceFilter) && experienceFilter != "-
1") // "-1" can be used for "All Experiences"
{
dt = dt.AsEnumerable()
.Where(row => row.Field<string>("AggregateName") ==
experienceFilter)
.CopyToDataTable();
}

// Group data by AggregateName, then HotspotName, and finally by Levels


var groupedData = dt.AsEnumerable()
.GroupBy(row => row.Field<string>("AggregateName"))
.Select(aggregateGroup => new
{
AggregateName = aggregateGroup.Key,
Hotspots = aggregateGroup.GroupBy(row =>
row.Field<string>("LevelName"))
.Select(hotspotGroup => new
{
LevelName = hotspotGroup.Key,
Levels = hotspotGroup.GroupBy(row =>
row.Field<long>("TermId"))
.Select(levelGroup => new
{
Level = levelGroup.Key,
TechConcepts =
levelGroup.Select(detail => detail.Field<string>("TechConcept")).ToList()
}).ToList()
}).ToList()
}).ToList();

DataTable outputDt = new DataTable();


outputDt.Columns.Add("AggregateName");
outputDt.Columns.Add("LevelName");

// Find the maximum level number


int maxLevel = dt.AsEnumerable().Max(row => row.Field<int>("Level"));

// Dynamically add columns for each level (Level 1, Level 2, etc.)


for (int i = 1; i <= 5; i++)
{
outputDt.Columns.Add($"Level {i}");
}

// Populate the output DataTable


foreach (var aggregate in groupedData)
{
foreach (var hotspot in aggregate.Hotspots)
{
int maxConcepts = hotspot.Levels.Max(level =>
level.TechConcepts.Count);

// Loop through each TechConcept and create a row for each one
for (int i = 0; i < maxConcepts; i++)
{
DataRow row = outputDt.NewRow();

// Always set the AggregateName (Experience) for each row


row["AggregateName"] = aggregate.AggregateName;
// Set the LevelName (Hotspot)
row["LevelName"] = hotspot.LevelName;

// Set the TechConcepts for each level


foreach (var level in hotspot.Levels)
{
if (i < level.TechConcepts.Count)
{
row[$"Level {level.Level}"] =
level.TechConcepts[i];
}
else
{
row[$"Level {level.Level}"] = "";
}
}

outputDt.Rows.Add(row); // Add the row to the DataTable


}
}
}

// Bind the output DataTable to the GridView


GridView1.DataSource = outputDt;
GridView1.DataBind();
}

private DataTable GetTermValues()


{
// Assuming you have a method to execute your stored procedure and
return a DataTable
DataSet ds = SP_GetDataSet("SP_SC_Ddl_GetTerms", "");
DataTable dt = ds.Tables[0];
return dt;
}
public class ExperienceDetail
{
public int RMExpId { get; set; }
public string TechConcept { get; set; }
public string HotspotName { get; set; }
public int PagerID { get; set; }
public int AggregateId { get; set; }
public int TermId { get; set; }
public string AggregateName { get; set; }
public int Level { get; set; }
public string Description { get; set; }
public string Goalstmt { get; set; }
}
protected void ddlFilterExperience_SelectedIndexChanged(object sender,
EventArgs e)
{
string selectedValue = ddlFilterExperience.SelectedValue;
if (selectedValue == "-1")
{
BindGrid(null); // Bind all data if "Select Experience" is selected
}
else
{
// Bind grid with the selected experience name
string selectedExperience = ddlFilterExperience.SelectedItem.Text;
BindGrid(selectedExperience); // Pass the selected experience name
for filtering
}
}
}

You might also like