TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mazhar khan
1.6k
148
4.3k
Duplicate user are not allowing in gridview in ASP.NET C#
Nov 23 2015 7:03 AM
I have many checkbox lists for searching, but when I will search by Qualificatoin by clicking checkboxlist item Bachelor in Computer Application and Master in Computer Application then the record is not displayed in gridview because in Table_EducationInfo I have two times record of the same user. I need Duplicate items add as a single item in gridview because based on Qualification displaying Table_RegistrationInfoinfo table details. I need duplication records will be one time in grid view.
Follow database tables below.
Table_EducationInfo
sno Email qualification subject
1
[email protected]
Bachelor in Computer Application c language
2
[email protected]
Masster in Computer Application java
Table_RegistrationInfo
RegistrationId GivenName Email Nationality CellPhone ExperienceYear
1 Ravi
[email protected]
Indian +910000000 15
I create view to join multiple tables below is my view
SELECT dbo.Table_ApplicationsInfo.ApplicationId, dbo.Table_RegistrationInfo.GivenName, dbo.Table_RegistrationInfo.Email, dbo.Table_RegistrationInfo.Nationality,dbo.Table_RegistrationInfo.ExperienceYear, dbo.Table_RegistrationInfo.ExperienceMonth, dbo.Table_RegistrationInfo.CellPhone, dbo.Table_EducationInfo.Qualification, dbo.Table_ApplicationsInfo.AppliedPositionId, dbo.Table_ApplicationsInfo.Status, dbo.Table_EducationInfo.Subject, dbo.Table_EducationInfo.Class, dbo.Table_RegistrationInfo.Title, dbo.Table_RegistrationInfo.RegistrationId FROM dbo.Table_RegistrationInfo INNER JOIN dbo.Table_ApplicationsInfo ON dbo.Table_RegistrationInfo.Email = dbo.Table_ApplicationsInfo.AppliedCandidateId INNER JOIN dbo.Table_EducationInfo ON dbo.Table_RegistrationInfo.Email = dbo.Table_EducationInfo.Email
Below is my select query for displaying base on Qualication in stored procedure.
select DISTINCT Email ,RegistrationId,GivenName,Nationality,CellPhone,ExperienceYear,Title from View_Seach_ByPositionIdStatus where Status=@Status and Qualification=@FilterValue and AppliedPositionId=@PositionId group by Email ,RegistrationId,GivenName,Nationality,CellPhone,ExperienceYear,Title
In query getting correct counts but in code duplicate duplicate items are not added, as given below code comments line.
Below is my .cs code.
private DataTable list(String dbObject, String filterName, String filterValue,string PositonId,string Status)
{
NameValuePairList objNameValuePairList = new NameValuePairList();
objNameValuePairList.Add(new NameValuePair("@FilterValue", filterValue, PositonId, Status));
objNameValuePairList.Add(new NameValuePair("@Action", "FilterBy" + filterName, PositonId, Status));
DataTable dt = dl.Search_RegisterationInfo(dbObject, objNameValuePairList, PositonId, Status);
return dt;
}
public DataTable list(String dbOject, FilterList myFilterList,string PositonId,string Status)
{
// gets a collection(dataset) of all unique filters(datatables) and also group all subfilters(rows) under each filter
DataTable dt;
DataSet ds = new DataSet();
// a filter may be a Nationality or a Qualification
foreach (Filter item in myFilterList)
// a subfilter may be Indian or Expatriate under the filter Nationality
{
// another subfilter may be Bachelor degree or Master Degree under the filter Qualification
dt = list(dbOject, item.getFilterName, item.getFilterValue, PositonId,Status);
dt.TableName = item.getFilterName;
// datatables are named based on the filters
if (ds.Tables.Count == 0)
// so we get a collection of unique filters (datatables) in the dataset
ds.Tables.Add(dt);
// add new filter without checking, since for the first time, no conflicts are possible
else
{
bool tableMatchFound = false;
foreach (DataTable newdt in ds.Tables)
if (newdt.TableName == dt.TableName)
{
// see if filter is already present in the dataset
tableMatchFound = true;
// when the current filter is already present in the dataset
foreach (DataRow dr in dt.Rows)
ds.Tables[newdt.TableName].ImportRow(dr);
}
// importrow() adds distinct new subfilters to the existing filter, duplicate items are not added
if (!tableMatchFound)
ds.Tables.Add(dt);
}
// if the filter does not exist, add the new filter to the collection
}
// the entire collection of filters will contain duplicate items
// distinct items from the entire collection is filtered out in the next section
dt = ds.Tables[0].Clone();
// get the structure of the first filter as they all apply to the same table object
if (ds.Tables.Count == 1)
dt = ds.Tables[0];
// if there is only one filter, no filtering is required
else
// if there are more than one, compare each subfilter of every other filter with the subfilters of the first filter
foreach (DataRow dr in ds.Tables[0].Rows)
{
// each subfilter from the first filter is used as a pivot
int rowMatchFound = 1;
for (int i = 1; i < ds.Tables.Count; i++)
// search all filters except the first one
foreach (DataRow newdr in ds.Tables[i].Rows)
// select each subfilter from all the filter
if ((int)dr["RegistrationId"] == (int)newdr["RegistrationId"])
rowMatchFound++;
if (rowMatchFound == ds.Tables.Count)
// a match is found exactly once in all the filters
dt.ImportRow(dr);
// the final item is selected so that is is present in all the filters
}
return dt;
}
The above bold code is want to change, think so..
Thank you in advance
Reply
Answers (
1
)
Encode Subject in asp.net email
How to read list data in word file through c#?