In DatagridView it is showing like:-
Name Vinay
Name Rajesh
Name Ram
but i want like this in datagridview:-
Name
Vinay Tiwari
Rajesh A
Ram B
It's very urgent, please!
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khan Abrar AhmedPosted May 22, 2014, 5:17 AM
if you want to group the name column add the below method and pass the paramters to after data bind event
groupGridView(gridviewname,0,2,"Name");
public void groupGridView(GridViewRowCollection gvrc, int startIndex, int total, string labelName)
{
if ((total <= 0) || (gvrc == null) || (gvrc.Count == 0) )
{
return;
}
int i, count = 1;
Label ctrllbl, nextlbl;
ArrayList lst = new ArrayList();
lst.Add(gvrc[0]);
var ctrl = gvrc[0].Cells[startIndex];
ctrllbl = (Label)gvrc[0].Cells[startIndex].FindControl(labelName);
var prevControl = gvrc[0].Cells[0];
for (i = 1; i < gvrc.Count; i++)
{
TableCell nextCell = gvrc[i].Cells[startIndex];
TableCell prevCell = gvrc[i].Cells[0];
nextlbl = (Label)gvrc[i].Cells[startIndex].FindControl(labelName);
if (nextlbl != null && ctrllbl != null)
{
if (ctrllbl.Text == nextlbl.Text)
{
count++;
nextCell.Visible = false;
prevCell.Visible = false;
lst.Add(gvrc[i]);
}
else
{
if (count > 1)
{
ctrl.RowSpan = count;
prevControl.RowSpan = count;
groupGridView(new GridViewRowCollection(lst), startIndex, total - 1, labelName);
}
count = 1;
lst.Clear();
ctrl = gvrc[i].Cells[startIndex];
prevControl = gvrc[i].Cells[0];
ctrllbl = (Label)gvrc[i].Cells[startIndex].FindControl(labelName);
lst.Add(gvrc[i]);
}
}
}
if (count > 1)
{
ctrl.RowSpan = count;
prevControl.RowSpan = count;
groupGridView(new GridViewRowCollection(lst), startIndex, total - 1, labelName);
}
count = 1;
lst.Clear();
}