forum

Home / DeveloperSection / Forums / something wrong with gridview

something wrong with gridview

Anonymous User 2104 18-Dec-2014

I have a gridview and I have a DB. In my task 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 into GridView1_RowDataBound, I get an error that: "Specified argument was out of the range of valid values. Parameter name: index". The trace of debugger shows 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


Updated on 19-Dec-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By