Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to taking control of size of Gridview when its on edit mode and its not?

I would have my Gridview User Control In gray frame(its div tag) whether Gridview is in editmode or not, I did use Gridview's Width and Styles but it didn't work. How do I do this?

.GridViewStyle
{
 /*It didn't work*/
 width:50%;
}

Gridview when its in edit mode Gridview Which is in edit mode

Gridview when its not in edit mode Gridview Which is not in edit mode

like image 490
Mmd Avatar asked Dec 30 '11 13:12

Mmd


People also ask

How do I turn off edit in grid view?

To disable editing for the entire grid, setting the AllowEditing property to False either in the designer or in code.

What is GridView control explain the properties of GridView control?

The GridView control is used to display the values of a data source in a table. Each column represents a field, while each row represents a record. The GridView control supports the following features: Binding to data source controls, such as SqlDataSource. Built-in sort capabilities.

Is GridView a control?

GridView is a control used to display data in tables on a web page. It displays data in both rows and columns, where each column represents a field, and each row represents a record. GridView helps to perform key activities like Insert, Delete, Sorting, and Paging.


2 Answers

The issue is certainly the size of the <input /> text boxes when in edit mode

Add the <EditRowStyle> element to your gridview to give the edit row a CSS class

<asp:GridView ID="GridView1" runat="server">
    ...
    <EditRowStyle CssClass="GridViewEditRow" /> <%-- add this --%>
</asp:GridView>

Now you can control the size of the textboxes with CSS

.GridViewEditRow input[type=text] {width:50px;} /* size textboxes */
.GridViewEditRow select {width:50px;} /* size drop down lists */
like image 116
MikeM Avatar answered Oct 13 '22 11:10

MikeM


It seems some controls that are visible in edit mode (the textbox inputs mainly) have a certain width, making the entire grid too wide. Your browser will do the best it can to set the width of the table (which is what a gridview renders to), but if the contents are too wide, it will have to make it wider than you wanted it to.

Inspect the textbox elements with Firebug (if you're using Firefox), Developer Tools (Internet Explorer), ... See if they have a width set to them.

like image 35
Peter Avatar answered Oct 13 '22 10:10

Peter