0
我正在動態創建一個RadGrid並將它添加到GridTemplateColumns
。這些列中有文本框。
將數據綁定到網格後,用戶更改文本框並單擊保存按鈕後,我想訪問文本框的值。但我被困在獲取文本框實例。我甚至無法抓住GridItems!
爲了增加更多的複雜性,我的RadGrid在UserControl中,它處於(多)視圖中。
繼承人的代碼。Telerik Radgrid如何從動態生成的RadGrid列中檢索文本框的值?
protected void Page_Init(object sender, EventArgs e)
{
DefineGridStructure();
}
protected void Page_Load(object sender, EventArgs e)
{
if (RadGrid1 != null && RadGrid1.Items.Count > 0)
{
string strtxt = ((TextBox)RadGrid1.Items[1]["ProductGroup1"].Controls[0]).Text;//For starters, load one control and check it's state
}
}
private void DefineGridStructure()
{
RadGrid1 = new RadGrid();
RadGrid1.AutoGenerateColumns = false;
RadGrid1.ShowHeader = true;
RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
foreach(GridColumn qtyColumn in BuildGridQtyColumns(PaxColumnCount))
{
RadGrid1.MasterTableView.Columns.Add(qtyColumn);
}
//Add grid to page
phRadGrid.Controls.Add(RadGrid1);
}
private List<GridColumn> BuildGridQtyColumns(int count)
{
List<GridColumn> qtyColumns = new List<GridColumn>();
for (int i = 1; i <= count; i++)
{
string qtyColumnName = string.Format("ProductGroup{0}", i);
GridTemplateColumn qtyColumn = new GridTemplateColumn();
qtyColumn.ItemTemplate = new GridNumberTemplate(qtyColumnName);//Creates a textbox control
qtyColumn.UniqueName = qtyColumnName;
qtyColumn.HeaderText = "Qty";
qtyColumn.HeaderStyle.Width = Unit.Pixel(60);
qtyColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
qtyColumns.Add(qtyColumn);
}
return qtyColumns;
}
由於我的控件在視圖中,因此涉及此視圖的每個操作都會多次調用Page_Init。
我想通了,不會的ViewState恢復到網頁的加載方法執行和多數民衆的原因項目計數總是0 Init方法。更新了代碼以在Load上定義Init和Load狀態上的結構。現在它解決了,這會讓我回到我原來的問題。 http://stackoverflow.com/questions/9611453/telerik-radgrid-can-we-save-a-unique-value-against-each-column。 – 2012-03-09 00:47:14