Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set Grid view column width for dynamic data

This is my code it's showing error..please any one give me the solution or other method.

C#
protected void Gridname_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Gridname.Columns[1].ItemStyle.Width = 10;
            Gridname.Columns[2].ItemStyle.Width = 40;
        }
    }

then its showing error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Posted
Updated 24-Apr-13 21:08pm
v3

using ItemStyle-width property.
Example:
<asp:templatefield headertext="Question" itemstyle-width="500px" sortexpression="question">
<itemtemplate>

<%# Eval("question")%>

 
Share this answer
 
v2
 
Share this answer
 

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