Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:41:33+00:00 2026-05-27T00:41:33+00:00

i want to set gridview column itemstyle wrap to false in c# code. how

  • 0

i want to set gridview column itemstyle wrap to false in c# code. how to do that?

iam binding gridview from c# code so in .aspx page there are no columns tag in gridview.

i tried Gridview1.columns[5].itemstyle.wrap = false.

but it gives me error like

ERROR-Index was out of range. Must be non-negative and less than the size of the collection

please help me.

my code is

 GridView1.DataKeyNames = new string[] { "MemberId" };
        if (Page.IsPostBack)
        {
            if (TextBox1.Text != "")
            {
                SqlConnection con = new SqlConnection(str);
                con.Open();

                string search = TextBox1.Text + "%";


                string query = "Select DISTINCT Designation +' '+FName+ ' ' +MName+ ' ' +LName as Name,"
             + " HomePhone,MobileNo1,"
             + " UPPER(ResAddr1) ++'  '+ UPPER(Resaddr2) ++'  '+ UPPER(ResAddr3) ++'  '+ UPPER(Resaddr4) ++'  '+ UPPER(Resaddr5) ++'  '+ UPPER(Resaddr6) ++'  '+ Pincode ++'  '+City as Address,"
             + " g.Category,f.GroupName as 'Group',Seats,"
             + " dbo.CONCATWTOTSHOW(d.MemberId,d.GID,d.CID)As SeatNo,"
             + " AmountExpected,AmountReceived,Discount,AmountPending,b.Remarks as Reference,b.SplRemarks, (d.MemberId)"
             + " from Person_Master a INNER JOIN Member_Master b ON a.PersonId=b.PersonId"
             + " LEFT JOIN Payment_Master c ON b.MemberId = c.MemberId"
             + " INNER JOIN SeatAssign_Master d ON b.MemberId = d.MemberId"
             + " INNER JOIN Year_Master e ON b.Year = e.Id"
             + " INNER JOIN Group_Master f ON d.Gid=f.Gid"
             + " INNER JOIN Category_Master g ON d.Cid=g.Cid "
             + " where b.Year=" + DDLYear.SelectedValue.ToString() + " and FName + ' ' + LName like '" + search + "' and b.Active=1 and d.Active=1 ";

                SqlCommand cmd = new SqlCommand(query, con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                    Label1.Text = "No Records Found !!!";
                    TextBox1.Text = "";

                }
                else
                {
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                    Label1.Text = "";
                    TextBox1.Text = "";

                }
            }

        }

.aspx code is

  <asp:GridView ID="GridView1"  runat="server" style="width:120%;font-size:12px;font-family:Tahoma;" 
         BackColor="White" BorderColor="#CC9966" BorderStyle="None" 
         BorderWidth="1px" CellPadding="4" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" 
            AutoGenerateDeleteButton="True" onrowdeleting="GridView1_RowDeleting" 
            onrowcreated="GridView1_RowCreated" >    
            <Columns>
            <asp:CommandField ShowSelectButton="True" SelectText="Edit" />

            </Columns>

        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
        <RowStyle BackColor="White" ForeColor="#330099" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
        <SortedAscendingCellStyle BackColor="#FEFCEB" />
        <SortedAscendingHeaderStyle BackColor="#AF0101" />
        <SortedDescendingCellStyle BackColor="#F6F0C0" />
        <SortedDescendingHeaderStyle BackColor="#7E0000" />
    </asp:GridView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:41:33+00:00Added an answer on May 27, 2026 at 12:41 am

    Data should exists in supplied DataSource and the number of columns must be greater or equal to the index of unwrapping column.

    GridView1.DataSource = ds.Tables[0];
    GridView1.DataBind();
    if (ds.Tables[0].Rows.Count > 0)
    {
         int numberOfColumn = ds.Tables[0].Columns.Count;
         if (numberOfColumn >= 5) // Since the 5th column you want to unwrap
         GridView1.Columns[5].ItemStyle.Wrap = false;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView on my page. I want to set a cell click
I want to set the backgroun color for a GridViewColumn that is databound inside
So, I have a GridView with an ObjectDataSource, and I want to programmatically set
I want to use the GridView mode of a ListView to display a set
I want set Listbox background to transparent but not working Is there any idea?
I want to set something up so that if an Account within my app
I want to set a background image for a div, in a way that
I'm binding a GridView to a collection of objects that look like this: public
My problem is that I want a grid that is populated with a set
I want to set datatable header column fields to a Label controls Text property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.