---
title: "something wrong with gridview"  
description: "something wrong with gridview"  
author: "Anonymous User"  
published: 2014-12-18  
updated: 2014-12-19  
canonical: https://www.mindstick.com/forum/12790/something-wrong-with-gridview  
category: "asp.net"  
tags: ["c#", "gridview"]  
reading_time: 1 minute  

---

# something wrong with gridview

I have a [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) and I have a DB. In my [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread) I bind GridView to DB and want to change the width of every column.

```
dataAdapter = new SqlDataAdapter("SELECT *  FROM Turs", sqlcn);dt = new DataTable("Turs");dataAdapter.Fill(dt);GridView1.DataSource = dt;GridView1.DataBind();
```

If I add [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) into GridView1_RowDataBound, I get an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) that: "Specified argument was out of the [range](https://www.mindstick.com/articles/23243/complete-troubleshooting-tips-for-belkin-n300-range-extender-setup) of valid values. [Parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide): [index](https://www.mindstick.com/blog/198/index-in-sql-server)". The [trace](https://www.mindstick.com/interview/1075/why-are-there-five-tracing-levels-in-system-diagnostics-traceswitcher) of debugger [shows](https://yourviews.mindstick.com/view/81380/new-york-violent-shooting-shows-people-are-not-safe-in-night-life) me that GridView1 has only 1 column. Why? In DB I have 8 columns.

```
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        e.Row.Cells[0].Width = 100;        e.Row.Cells[1].Width = 150;    }
```

Regards

## Replies

### Reply by Anonymous User

You should be doing it like this way instead by creating a DataSet

```
DataSet ds = new DataSet();dataAdapter.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();
```

### Reply by Anonymous User

You need to check RowType in the GridView1_RowDataBound event.

Try this

```
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e){        if(e.Row.RowType == DataControlRowType.DataRow)        {           
e.Row.Cells[0].Width = 100;           
e.Row.Cells[1].Width = 150;        }}
```


---

Original Source: https://www.mindstick.com/forum/12790/something-wrong-with-gridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
