Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my friends
i showing data in gridview
C#
string sql = "select * "                                                                                                 + "   from table_name where t.months = '2014/05'"
                      + " order by 1 DESC";

           OracleCommand command = new OracleCommand(sql, conn);
           command.CommandType = CommandType.Text;
           OracleDataAdapter adapter = new OracleDataAdapter(command);

           DataSet dataset = new DataSet();
           adapter = new OracleDataAdapter(command);
           adapter.Fill(dataset);

           command.ExecuteNonQuery();
           GridView1.DataSource = dataset.Tables[0];
           GridView1.DataBind();

i am facing problem when i write
C#
GridView1.Columns[1].HeaderText = "mytext";


it showing Error :

Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index

can any body help me PLZ


thanks
Posted
Updated 8-May-14 1:47am
v2
Comments
MNamrata 8-May-14 7:23am    
How much columns are present in your gridview?
mohd598 8-May-14 8:49am    
8 column
Thanks7872 8-May-14 7:48am    
Delete the code you posted as a solution. I updated question with the same.

Make sure your column index starting from "0" while giving into the columns, and you should enter the column index in between the range of your total columns
 
Share this answer
 
Comments
Thanks7872 8-May-14 7:39am    
Make sure your column index starting from "0"???
Jagbir Saini 8-May-14 7:42am    
Means while counting the columns in the gridview, make sure your counting starting from 0.
mohd598 8-May-14 8:52am    
thanks, but let me konw more about it
try this

GridView1.HeaderRow.Cells[i].Text="ABC";
 
Share this answer
 
Comments
MNamrata 8-May-14 9:13am    
Plz comment on corresponding solution. Dnt submit new solution.<br>
 <br>
GridView1.HeaderRow.Cells[1].Text="ABC";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900