Question

I can not find post that resolve my problem. I saw many times a Add method or Insert method for adding a row but I have not get them !! I work with .NET 4.5

I would like to show you a printscreen in order to demonstrate that I do not dispose these methods, but I can not because I am too novice to have this right :/

I need to create a gridview (not a datagridview) programmatically with one column and several rows. I populate rows manually. If I understand, I must proceed like this : create gridview, then a column that I add to gridview, then a row that I add to column, and then a tablecell that I add to row. Is that the good way to do ?

This is my code :

    GridView listTypeBot = new GridView();
   // Create my column
   BoundField bf = new BoundField();
   bf.HeaderText = "Types of bot available";
   // Add my column to my gridview
   listTypeBot.Columns.Add(bf);
   // Create a row and a cell
   GridViewRow gvr = listTypeBot.Rows[0];  // I have an exception here : out of range. When I watch my gridview, it does not have row.
   TableCell tc = new TableCell();
   tc.Text = name;
   // Add cell to my row
   gvr.Cells.Add(tc);
   listTypeBot.Rows[0].Cells.Add(tc);

I think I get this exception because listTypeBot does not have any row. How can I add it please ?

Thanks in advance.

Was it helpful?

Solution

why not just use the DataSource to bind the data in your case the data source is the RSS ? and set AutoGenerateColumns to rue , something like that :

 List<string> names = new List<string>();
 names.Add(" the alghabban  ");
 GridView newGrid = new GridView();                         
 newGrid.DataSource = names;
 newGrid.DataBind(); 

and when you need to add row just add it to names and bind the Grid view again

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top