У меня есть 2 Gridvies первые данные загрузки страниц, а на кнопке редактирования появляется новая добавленная строка. Затем он создает сетку в этой строке, проблема в том, что когда есть сообщение, мне нужно, чтобы эта строка воссоздана. В моем коде недавно добавленный обработчик события редактирования GridView не срабатывает, я должен иметь возможность воссоздать эту строку при обратной передаче и иметь GridView, который запускает отправку сообщения обратно в режим редактирования. Я не знаю, что делать в этот момент, может кто-нибудь мне помочь, вот мой код. кстати PageSettings является GridView и WebservicesGrid является вложенным одинВложенная Gridview и недавно созданная строка исчезает при обратной передаче
protected void PageSettings_RowEditing(object sender, GridViewEditEventArgs e)
{
((GridView)sender).EditIndex = e.NewEditIndex;
EditIndex = e.NewEditIndex;
lblStatus.Text = string.Format("Editing Row: {0}", (e.NewEditIndex + 1).ToString());
}
public int EditIndex = -1;
protected void PageSettings_DataBound
(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0 &&
((GridView)sender).EditIndex == EditIndex
||
Request["__EVENTTARGET"] == "ctl00$MainContent$PageSettings$ct103$WebServicesGridView")
{
GridViewRow row = new GridViewRow(e.Row.RowIndex+ 2, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
row.CssClass = "gridview-alternating-row";
//row.Cells.AddRange(CreateCells());
TableCell cell;
cell = new TableCell();
cell.ColumnSpan = 2;
row.Cells.Add(cell);
cell = new TableCell();
cell.ColumnSpan = 4;
SystemPage SysPage = e.Row.DataItem as SystemPage;
GridView gv = CreateGridView("WebServices", SysPage);
cell.Controls.Add(gv);
row.Cells.Add(cell);
// Row Edting Event not firing either
gv.RowEditing += new GridViewEditEventHandler(services_RowEditing);
Table table = e.Row.Parent as Table;
table.Rows.AddAt(e.Row.RowIndex + 2, row);
}
}
private GridView CreateGridView(string type, SystemPage page)
{
GridView services = new GridView();
switch (type)
{
case "WebServices" :
CommandField CommandEdit = new CommandField();
CommandEdit.ButtonType = ButtonType.Link;
CommandEdit.ShowEditButton = true;
CommandEdit.UpdateText = "Update";
CommandEdit.EditText = "Edit";
services.Columns.Add(CommandEdit);
BoundField WebServiceName = new BoundField();
WebServiceName.DataField = "name";
WebServiceName.HeaderText = "WebService";
services.Columns.Add(WebServiceName);
BoundField WebServiceUrl = new BoundField();
WebServiceUrl.DataField = "url";
WebServiceUrl.HeaderText = "Url";
services.Columns.Add(WebServiceUrl);
List<WebService> list = new List<WebService>();
list.Add(new WebService { Name = "Test", Url = "Test" });
services.ID = "WebServicesGridView";
services.AutoGenerateColumns = false;
services.DataSource = list;
services.DataBind();
break;
}
return services;
}
protected void services_RowEditing(object sender, GridViewEditEventArgs e)
{
((GridView)sender).EditIndex = e.NewEditIndex;
lblSubGridStatus.Text = e.NewEditIndex.ToString();
PageSettings.DataBind();
}
Вы ** действительно ** должны переосмыслить свой подход здесь. Создание «GridViews» или других элементов управления программно - очень плохая идея из-за всех проблем, с которыми вы столкнулись. Можете ли вы определить свой второй «GridView» в разметке, а hen показать/скрыть его в зависимости от состояния строки? Думаю, это будет хорошее начало. – jwiscarson