![](/img/trans.png)
[英]Getting the Header Rows Count of Multi Column Header in WebDataGrid, Infragistics
[英]Infragistics WebDataGrid Checkbox and hidden column problems
我正在嘗試隱藏“鍵”或[0]列。 我也試圖在下面的代碼中設置復選框,最終用戶可以單擊/取消單擊。 默認情況下,我將復選框設置為未選中狀態。
這段代碼dgvPunchs.Columns[0].Hidden = true;
是我發現如何隱藏列的方法,但是由於以下錯誤而出錯。
“你調用的對象是空的。”
當前還顯示復選框,但是最終用戶無法單擊它們。 我感到困惑。 請幫忙! :)
protected void GenerateSalaryPunchesTable()
{
this.dgvPunchs.Rows.Clear();
string[] DateRange = this.cboPayPeriods.SelectedItem.Text.ToString().Replace(" ", "").Split('-');
DataTable pDates = new DataTable();
pDates.Columns.Add("Key");
pDates.Columns.Add("Date", System.Type.GetType("System.DateTime")); // Date Cell
pDates.Columns.Add("Worked", System.Type.GetType("System.Boolean")); //Worked CB
pDates.Columns.Add("Vaction", System.Type.GetType("System.Boolean")); //Vacation CB
pDates.Columns.Add("Sick", System.Type.GetType("System.Boolean")); //Sick CB
pDates.Columns.Add("Holiday", System.Type.GetType("System.Boolean")); //Holiday CB
pDates.Columns.Add("Error", System.Type.GetType("System.String")); //Error
foreach (DataColumn col in pDates.Columns)
{
col.ReadOnly = false;
}
pDates.Columns["Key"].ColumnMapping = MappingType.Hidden;
while (Convert.ToDateTime(DateRange[0]) <= Convert.ToDateTime(DateRange[1]))
{
if (Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Saturday & Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Sunday)
{
DataRow nRow = pDates.NewRow();
nRow["Key"] = Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
nRow["Date"]= Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
nRow["Worked"] = 0;
nRow["Vaction"] = 0;
nRow["Sick"] = 0;
nRow["Holiday"] = 0;
nRow["Error"] = "";
pDates.Rows.Add(nRow);
}
DateRange[0] = Convert.ToDateTime(DateRange[0]).AddDays(1).ToShortDateString();
}
dgvPunchs.DataSource = pDates;
dgvPunchs.DataBind();
dgvPunchs.Columns[0].Hidden = true;
}
您需要在WebDataGrid中手動創建列,如果沒有,則只需檢查columns.count,它將等於0。
因此,您可以在WebDataGrid的init事件中執行此操作(在設置WebDataGrid1.datasource並使WebDataGrid1.autogenertecolumns = false之前):
Infragistics.Web.UI.GridControls.BoundDataField f;
Infragistics.Web.UI.GridControls.EditingColumnSetting columnSettingReadOnly;
foreach (System.Data.DataColumn c in pDates.Columns)
{
f = new Infragistics.Web.UI.GridControls.BoundDataField(true);
f.DataFieldName = c.ColumnName;
f.Key = c.ColumnName;
f.Header.Text = c.ColumnName;
WebDataGrid1.Columns.Add(f);
// In order to set it as readonly:
columnSettingReadOnly = New Infragistics.Web.UI.GridControls.EditingColumnSetting();
columnSettingReadOnly.ColumnKey = f.Key;
columnSettingReadOnly.ReadOnly = True;
WebDataGrid1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(columnSettingReadOnly);
}
嘗試以上,讓我們知道。
PS:不確定顯示復選框的列的問題不允許您對其進行檢查...
我必須將所有列的標記添加到html端。 關閉AutoGenerateColumns,我打開EnableAjaxViewState和EnableDataViewState不確定是否需要這些。 但是通過將其添加到HTML中,我便能夠調用代碼
ig:WebDataGrid ID =“ dgvPunchs” runat =“ server”寬度=“ 800px” DataKeyFields =“ Key” AutoGenerateColumns =“ False” EnableAjaxViewState =“ True” EnableDataViewState =“ True”>
<Columns>
<ig:BoundDataField DataFieldName="Key" Key="Key">
<Header Text="Key" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="Date" Key="Date">
<Header Text="Date" />
</ig:BoundDataField>
<ig:BoundCheckBoxField DataFieldName="Worked"
Key="Worked">
<Header Text="Worked" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Vaction"
Key="Vaction">
<Header Text="Vaction" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Sick"
Key="Sick">
<Header Text="Sick" />
</ig:BoundCheckBoxField>
<ig:BoundCheckBoxField DataFieldName="Holiday"
Key="Holiday">
<Header Text="Holiday" />
</ig:BoundCheckBoxField>
<ig:BoundDataField DataFieldName="Error" Key="Error">
<Header Text="Error" />
</ig:BoundDataField>
</Columns>
<Behaviors>
<ig:EditingCore>
<Behaviors>
<ig:CellEditing>
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
</Behaviors>
dgvPunchs.DataSource = pDates;
dgvPunchs.DataBind();
dgvPunchs.Columns[0].Hidden = true;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.