Solved

Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments

Posted on 2009-04-06
7
5,697 Views
Last Modified: 2013-12-17
I have used code to merge cells in gridview but it shows error


 Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments


so can you help your suggest anything for the same???????
public static List<T> MakeList_tmp<T>(T temp)
        {
            List<T> newList = new List<T>();
            return newList;
        }
 
 
 
        private void mergeRows(GridView gv)
        {
            string lastColumn1 = string.Empty;
            
            GridViewRow currentRow = null;
            GridViewRow tmp = null;
            var temp = tmp;
            var tempRow = MakeList_tmp(temp);
            System.Collections.Generic.List tempRows = new System.Collections.Generic.List();
            
            foreach (GridViewRow row in gv.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    string currentColumn1 = string.Empty;
                    currentColumn1 = Convert.ToString(row.Cells[0].Text);
 
                    if (currentRow == null)
                    {
 
                        currentRow = row;
                        lastColumn1 = Convert.ToString(row.Cells[0].Text);
 
                    }
 
 
                    else
                    {
                        if (lastColumn1 != currentColumn1)
                        {
 
                            currentRow.Cells[0].RowSpan = tempRows.Count + 1;
                            currentRow.Cells[0].VerticalAlign = VerticalAlign.Middle;
                            currentRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;
 
                            foreach (GridViewRow row1 in tempRows)
 
                                row1.Cells.RemoveAt(1);
                            lastColumn1 = currentColumn1;
 
                            tempRows.Clear();
                            currentRow = row;
                            lastColumn1 = currentColumn1;
                        }
                        else
                        {
 
                            tempRows.Add(row);
                        }
                    }
                }
            }
           
            if (tempRows.Count >= 0)
            {
                
                currentRow.Cells[0].RowSpan = tempRows.Count + 1;
                currentRow.Cells[0].VerticalAlign = VerticalAlign.Middle;
                currentRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;
 
                foreach (GridViewRow row1 in tempRows)
                    row1.Cells.RemoveAt(0);
            }
        }
protected void GridView1_PreRender(object sender, EventArgs e)
        {
            GridView gv1 = (GridView)sender;
            mergeRows(gv1);
 
        }

Open in new window

0
Comment
Question by:scspl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24074963
what about this:
public static List<T> MakeList_tmp<T>()   // if you need and argument, it shall by <T> temp and not T temp, AFAIK
        {
            List<T> newList = new List<T>();
            return newList;
        }
 
and later: 

     private void mergeRows(GridView gv)
        {
            string lastColumn1 = string.Empty;
            
            GridViewRow currentRow = null;
            GridViewRow tmp = null;
            List<GridViewRow> tempRows = MakeList_tmp();
            ...

Open in new window

0
 

Author Comment

by:scspl
ID: 24074994
So, if here

GridViewRow tmp = null;

List<GridViewRow> tempRows = MakeList_tmp();


i want to pass tmp with MakeList_tmp(tmp) so

how it should be written over here and how the argument will be passed to

the MakeList_temp() <----    function....
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24075019
as I explained in the comment of the previous comment:
public static List<T> MakeList_tmp<T>(<T> tmp)  

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:scspl
ID: 24075094
it is not accepting that...

<T> tmp -->  is not a valid argument.....

so is there any other way...
public static List<T> MakeList_tmp<T>(<T> tmp)   
{
    List<T> newList = new List<T>();
    return newList;
}
 
 
 
 
// Above code generates the error:->
 
// Compiler Error Message: CS1031: Type expected

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24075111
sorry, in the method parameter data type, it's without the <>
public static List<T> MakeList_tmp<T>(T tmp)   
{
    List<T> newList = new List<T>();
    return newList;
}
 

Open in new window

0
 

Author Comment

by:scspl
ID: 24075126
That matter is solved but tell me one thing

where will  the method  mergeRows() called?

will it be before databinding or after that???
0
 

Author Comment

by:scspl
ID: 24075141
now i got it it's working thanks a lot for your help


it will be called after binding the data to the data grid

other wise it will show the null reference error.

because it will not have any data into cells without binding..



thank you

again angel
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question