Solved

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

Posted on 2009-04-06
7
5,567 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
  • 4
  • 3
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
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 142

Assisted Solution

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

Open in new window

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:scspl
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now