2014年7月13日 星期日

[RESOLVED] How to set width of the gridview ?


How to set width of the gridview ....i have tried some code to change the width of the gridview but it is not working... It is settting width according to data in the columns ..plz help


Here is my code ....


 protected void gvDFR_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        //e.Row.Cells[0].Width = 1000;

        e.Row.Cells[1].Visible = false;



          

        e.Row.Cells[2].Width = 1000;

        e.Row.Cells[3].Width = 1000;

        e.Row.Cells[4].Width = 1000;

        e.Row.Cells[5].Width = 1000;

        e.Row.Cells[6].Width = 1000;

        e.Row.Cells[7].Width = 1000;

        e.Row.Cells[8].Width = 1000;

        e.Row.Cells[9].Width = 1000;

        e.Row.Cells[10].Width = 1000;











        int i = gvDFR.Rows.Count;



        lblTotalRec.Text = i.ToString();

    }



Why dont you specify them in the UI?


It might be possible that adding px or % can make it work, but that is a guess.


try setting the width of the gridview from the UI, by specifying the width in the ItemStyle of the ItemTemplate.



Hi rohankota,


You can do that on the OnRowDataBound event of the gridview.


protected void gvDFR_RowDataBound(object o, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Width = new Unit("200px");
e.Row.Cells[1].Width = new Unit("400px");
// and so on
}
}

Add this to your Gridview Markup


        onrowdatabound="gvDFR_RowDataBound">    // just add this event and execute the above code

or else:


http://stackoverflow.com/questions/6015885/set-each-column-of-grid-view-to-different-width


Hope this helps.


Thanks,


Jatin







hello


rohan


you can give width to gridview using multiple options


1  you can use row databound event to give width


protected void gvDFR_RowDataBound(object sender, GridViewRowEventArgs e)
{

gvDFR.Columns[0].ItemStyle.Width =10 ;

}

2) you can specify width to columns on aspx page using


   











沒有留言:

張貼留言