2011-10-19 88 views
-1
 <div style="padding-top: 10px; padding-right: 15px; padding-bottom: 25px"> 
    <div class="table"> 
     <div> 
      <asp:GridView ID="gvList" runat="server" AutoGenerateColumns="false" 
     DataKeyNames="UserId" AllowSorting="true" onrowcreated="gvList_RowCreated" 
    onrowdatabound="gvList_RowDataBound" 
    onsorting="gvList_Sorting"> 
       <AlternatingRowStyle CssClass="even" /> 
       <EmptyDataTemplate> 
        Records for selected criteria do not exist 
       </EmptyDataTemplate> 

       <Columns> 
     <asp:TemplateField> 
     <ItemStyle Width="2%"/> 
     <HeaderTemplate> 
      <asp:Label ID="lblSelect" runat="server" Text="<%$ Resources:LBShowcaseRes,lblSelect %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
      <asp:CheckBox ID="chkSelect" runat="server" /> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle width="15%"/> 
     <HeaderTemplate> 
     <asp:LinkButton ID="lnkFirstName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblFirstName %>" CommandName="Sort" CommandArgument="FirstName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
      <asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="18%"/> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkLastName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblLastName %>" CommandName="Sort" CommandArgument="LastName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="20%"/> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkEmailId" runat="server" Text="<%$ Resources:LBShowcaseRes,lblEmailid %>" CommandName="Sort" CommandArgument="EmailAddress"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblEmailId" runat="server" Text='<%# Eval("EmailAddress") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="15%" /> 
     <HeaderTemplate> 
       <asp:Label ID="lblUserName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblUserName %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:TextBox ID="txtUserName" runat="server" Text='<%# Eval("UserName") %>' MaxLength="75" Width="100px" EnableViewState="true"></asp:TextBox> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="10%" /> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkOffice" runat="server" Text="<%$ Resources:LBShowcaseRes,lblOffice %>" CommandName="Sort" CommandArgument="OfficeName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblOffice" runat="server" Text='<%# Eval("OfficeName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="20%" /> 
     <HeaderTemplate> 
       <asp:Label ID="lblRolePrompt" runat="server" Text="<%$ Resources:LBShowcaseRes,lblRole %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:HiddenField ID="hdnRole" runat="server" Value='<%# Eval("RoleName") %>' /> 
       <asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true"> 
       </asp:DropDownList> 
     </ItemTemplate> 
     </asp:TemplateField> 

    </Columns> 
      </asp:GridView> 

     </div> 


     <div class="table-nav"> 
     <asp:Button ID="btnDelete" runat="server" Text="<%$ Resources:LBShowcaseRes,btnDelete %>" SkinID="leftButton" 
      OnClientClick="var values= GetSelectedUser();return ConfirmDeleteWithValues('Please select at least one User for deletion.',values);" 
      onclick="btnDelete_Click" />    
     <asp:Button ID="btnPrintExport" runat="server" Text="<%$ Resources:LBShowcaseRes,btnPrintRep %>" CausesValidation="false"/> 
     <asp:Button ID="btnSave" runat="server" OnClientClick="return ConfirmAddUser();" 
      Text="<%$Resources:LBShowcaseRes,btnSave %>" 
      onclick="btnSave_Click" /> 
     </div> 
     <div class="clear"> 
     </div> 
    </div> 
</div> 

我的表css是 表{border-collapse:collapse;寬度:100%}Gridview寬度超出邊界bcz內容寬度更大

現在,當我運行該頁面的GridView寬度超出100%bcz的內容寬度是非常大的...所以我想這樣做,它應該在達到寬度後打破內容該列應該怎麼辦PLZ幫我.......

修改 記錄爲選擇的標準是不存在的

    <Columns> 
     <asp:TemplateField> 
     <ItemStyle Width="20px"/> 
     <HeaderTemplate> 
      <asp:Label ID="lblSelect" runat="server" Text="<%$ Resources:LBShowcaseRes,lblSelect %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
      <asp:CheckBox ID="chkSelect" runat="server" /> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle width="35px"/> 
     <HeaderTemplate> 
     <asp:LinkButton ID="lnkFirstName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblFirstName %>" CommandName="Sort" CommandArgument="FirstName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
      <asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="35px"/> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkLastName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblLastName %>" CommandName="Sort" CommandArgument="LastName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="35px"/> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkEmailId" runat="server" Text="<%$ Resources:LBShowcaseRes,lblEmailid %>" CommandName="Sort" CommandArgument="EmailAddress"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblEmailId" runat="server" Text='<%# Eval("EmailAddress") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="35px" /> 
     <HeaderTemplate> 
       <asp:Label ID="lblUserName" runat="server" Text="<%$ Resources:LBShowcaseRes,lblUserName %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:TextBox ID="txtUserName" runat="server" Text='<%# Eval("UserName") %>' MaxLength="75" Width="100px" EnableViewState="true"></asp:TextBox> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="35px" /> 
     <HeaderTemplate> 
       <asp:LinkButton ID="lnkOffice" runat="server" Text="<%$ Resources:LBShowcaseRes,lblOffice %>" CommandName="Sort" CommandArgument="OfficeName"></asp:LinkButton> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:Label ID="lblOffice" runat="server" Text='<%# Eval("OfficeName") %>'></asp:Label> 
     </ItemTemplate> 
     </asp:TemplateField> 

     <asp:TemplateField> 
     <ItemStyle Width="50px" /> 
     <HeaderTemplate> 
       <asp:Label ID="lblRolePrompt" runat="server" Text="<%$ Resources:LBShowcaseRes,lblRole %>"></asp:Label> 
     </HeaderTemplate> 
     <ItemTemplate> 
       <asp:HiddenField ID="hdnRole" runat="server" Value='<%# Eval("RoleName") %>' /> 
       <asp:DropDownList ID="ddlRole" runat="server" AppendDataBoundItems="true"> 
       </asp:DropDownList> 
     </ItemTemplate> 
     </asp:TemplateField> 

    </Columns> 
      </asp:GridView> 

     </div> 


     <div class="table-nav"> 
     <asp:Button ID="btnDelete" runat="server" Text="<%$ Resources:LBShowcaseRes,btnDelete %>" SkinID="leftButton" 
      OnClientClick="var values= GetSelectedUser();return ConfirmDeleteWithValues('Please select at least one User for deletion.',values);" 
      onclick="btnDelete_Click" />    
     <asp:Button ID="btnPrintExport" runat="server" Text="<%$ Resources:LBShowcaseRes,btnPrintRep %>" CausesValidation="false"/> 
     <asp:Button ID="btnSave" runat="server" OnClientClick="return ConfirmAddUser();" 
      Text="<%$Resources:LBShowcaseRes,btnSave %>" 
      onclick="btnSave_Click" /> 
     </div> 
     <div class="clear"> 
     </div> 
    </div> 
</div> 
+0

哪些內容非常大!!請提及它... – sikender

+0

in gidview lblEmailId content – user993634

+0

@ user993634,你說lblEmailId是最大的,但爲什麼你給了一些其他列的寬度和寬度與lblEmailId相同。將最大寬度僅限於emailid,並減小所有剩餘寬度。 –

回答

0

在你的代碼中,你沒有給你的gridview任何寬度。根據您的調整,將網格視圖的寬度也設爲100%,並將每個TemplateField的寬度從%的寬度更改爲正常數字。

編輯:

然後增加網格視圖也的高度,使得數據將調整並配合到表中。

+0

在gidview lblEmailId內容.. – user993634

+0

是我設置的寬度100%在gridview仍然不能正常工作... – user993634

+0

您是否已將TemplateField寬度從百分比更改爲某個寬度的數字? –

0

以像素(固定)而非百分比設置gridview寬度。如果您設置了持續時間寬度,那麼GridView寬度將以「div或表格或頁面寬度」進行調整。