We help IT Professionals succeed at work.
Troubleshooting Question

GridView

K Feening
K Feening asked
on
32 Views
Last Modified: 2020-07-26
Hi
I have a asp Gridview and need to fix 1 columns width see below

 

                                                  Need to fix Note Column Width to at least Half of displayed Note Column



Comment
Watch Question

CERTIFIED EXPERT

Commented:
you can set the Width property of a particular field,
but if you want to set it as a proportion of the max width, then you need to do postprocessing of the gridview display event
K FeeningProgrammer

Author

Commented:
Hi Robr
I Tried setting width as below, where do you set it, its not in the Gridview edit columns
width 100px gives error in aspx file
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="True" Visible="False" />
                        <asp:ButtonField ButtonType="Button" CommandName="Selection" HeaderText="Option" Text="Selection" />
                        <asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" Width="100px"/>
                        <asp:BoundField DataField="RemDays" HeaderText="Days" SortExpression="RemDays" />
                        <asp:BoundField DataField="RemDate" HeaderText="Date" SortExpression="RemDate" DataFormatString="{0:dd/MM/yyyy} "/>
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
K FeeningProgrammer

Author

Commented:
Hi Robr
Nearly worked I must have not copied Correctly see Image and code Below
The line with Configuration manager as text goes outside the Grid
and Last Display rtyrtyudtyudtyudtyudtyudtyudtyudtyudtyudty is same
I tried wrap="true"

<form id="form1" runat="server">
        <div>
        </div>
        <asp:SqlDataSource ID="dsNotes" runat="server" ConnectionString="<%$ ConnectionStrings:SchoolDataConnectionString %>" SelectCommand="SELECT [Note], [RemDays], [RemDate], [Id] FROM [SchoolNotes]"></asp:SqlDataSource>

        <asp:GridView ID="gvDesc" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id" DataSourceID="dsNotes" ForeColor="#333333" GridLines="None" PageSize="4" ShowHeaderWhenEmpty="True" Style="overflow: scroll; z-index: 1; left: 16px; top: 83px; position: absolute; height: 157px; width: 390px" SelectedIndexChanging="gvDesc_SelectedIndexChanging">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" Visible="False" />
                <asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Option" Text="Select" />
                <asp:TemplateField HeaderText="Notes" SortExpression="Notes" ItemStyle-Width="30em">
                    <EditItemTemplate>
                        <asp:TextBox CssClass="inp" ID="TextBox7" runat="server" Text='<%# Bind("Note") %>' Width="20em" Wrap="true"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("Note") %>' Width="20em" Wrap="true"></asp:Label>
                    </ItemTemplate>

                    <ItemStyle Width="6em"></ItemStyle>
                </asp:TemplateField>
                <asp:BoundField DataField="RemDays" HeaderText="Days" SortExpression="RemDays" />
                <asp:BoundField DataField="RemDate" DataFormatString="{0:dd/MM/yyyy} " HeaderText="Date" SortExpression="RemDate" />
            </Columns>
            <EditRowStyle BackColor="#7C6F57" />
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#E3EAEB" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F8FAFA" />
            <SortedAscendingHeaderStyle BackColor="#246B61" />
            <SortedDescendingCellStyle BackColor="#D4DFE1" />
            <SortedDescendingHeaderStyle BackColor="#15524A" />
        </asp:GridView>


    </form>


CERTIFIED EXPERT

Commented:
to get wrap to work the way you want (it is working, but only on space), i think you may need to use a disabled multiline text box, not a label.
K FeeningProgrammer

Author

Commented:
Thanks Robr
Multiline works but don't really want vertical slide bars
Found this was set to 2 % adjusted it to 0.6 % ( Original Code) and it gives the correct height for multiline data but too small for any data depending on width see image 1st, 2nd, 4th Lines OK  3rd line height incorrect
if there code like ( suggested Code) or can i do it on dataBinding in VB.net
is there Suggested Code 

if Eval("Note").ToString().Length < 350 Height= 18px, Height=Eval("Note").ToString().Length * 0.6& 
Original Code

<asp:TextBox TextMode="multiLine"  Width="400" Text='<%#Eval("Note") %>' Height='<%# Eval("Note").ToString().Length * 0.6%>'  ID="TextBox9" runat="server"></asp:TextBox>

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
K FeeningProgrammer

Author

Commented:
No the panel just displays over top of other databound will work with having slid bars that good
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.