2017-09-20 30 views
0

這是我的GridView時變化的時候,第一次加載頁面: enter image description hereASP.NET GridView的格式在編輯模式下

現在,這是個什麼樣子,當用戶點擊編輯按鈕,如: enter image description here

的在編輯模式下,GridView的格式顯然更好,所以我試圖編輯它的樣式,使它看起來總是那樣。我試圖在rowstyle中編輯寬度和高度,但這些設置僅適用於使單元格變大的情況,我顯然希望它們變小。我一直無法找到或編寫一種方法來以編程方式調整單元格大小。

這裏是爲GridView和SqlDataSource的代碼(我省略了這個職位的更新參數):

<div style="overflow:scroll; width:1500px"> 
      <asp:GridView id="maintenanceGridView" runat="server" 
       DataSourceID="maintenanceDataSource" 
       AllowSorting="true" AllowPaging="true" PageSize="50" 
       OnRowEditing="maintenanceGridView_RowEditing" 
       OnRowUpdating="maintenanceGridView_RowUpdating" 
       OnRowCancelingEdit="maintenanceGridView_RowCancelingEdit" 
       OnRowDataBound="maintenanceGridView_RowDataBound" 
       AutoGenerateEditButton="true"> 
       <rowstyle backcolor="LightCyan"/> 
       <alternatingrowstyle backcolor="PaleTurquoise"/> 
       <EmptyDataTemplate> 
        <h3>No Records Found!!</h3> 
       </EmptyDataTemplate> 
      </asp:GridView> 
     </div> 
     <asp:SqlDataSource id="maintenanceDataSource" 
      DataSourceMode="DataSet" 
      SelectCommand="AMT_GetMaintenanceView" 
      UpdateCommand="AMT_UpdateMaintenance" 
      UpdateCommandType="StoredProcedure" 
      ConnectionString="<%$ ConnectionStrings:iandcInternDBConn %>" 
      runat="server"> 
      <UpdateParameters> 
      </UpdateParameters> 
     </asp:SqlDataSource> 
</div> 

我不知道是什麼原因造成的GridView的格式改變。我試圖尋找它的默認CSS,但什麼也沒找到,Internet Explorer的開發者工具告訴我,CSS在編輯模式下和在視圖模式下是一樣的。

任何幫助或進一步的洞察力非常感謝。謝謝!

回答

0

組細胞RowDataBound事件編程寬度:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    e.Row.Cells[0].Width = Unit.Pixel(100); 
    e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Left; 
} 
+0

我把這些代碼在for循環中,因此將適用在所有細胞上。如果我使單元格大於當前值,它只會產生效果。感謝您的貢獻! –

0

我能夠始終迫使GridView控件進入編輯模式的第一行上找到一個小臨時的解決方法;即使用戶試圖取消編輯。

我通過將代碼添加到Page_Load和的RowDataBound事件,這樣做

protected void Page_Load(object sender, EventArgs e) 
{ 
     // Force the gridview into edit mode always becuase its formatting looks a million times better 
     GridView1.EditIndex = 0; 
} 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
     // Default to edit mode 
     if (GridView1.EditIndex == -1) 
      GridView1.EditIndex = 0; 
} 
0

嘗試增加這樣的事情在你的CSS:

.GridViewEditRow input[type=text] { /*for text boxes use td for every cell*/ 
     width: 50px; 
    } 
相關問題