首页 文章

从Telerik RadGrid开始读取/编辑值

提问于
浏览
0

我有这种情况:

A Telerik RadGrid

...带有数据的普通RadGrid . 并且,如果我连续clic,我想得到这个:

Another Telerik RadGrid

...标签 - 文本框对的列表(请注意:这些数据列表是从行中获取的,但不是它的一部分) .

有了第一个RadGrid,一切都还好 . 因此,我使用了一个简单的HTML表作为对的列表(在第二个图像中) . 此列表是从数据库生成的代码隐藏 .

The problem is the update of the TextBoxs :如果我编辑这些文本框并在Update Botton上执行clic,则启动myRadGrid_UpdateCommand方法 . 但是我可以't find a way to manage these textboxes (they don'出现在myRadGrid.Controls中,否则) .

所以我试图在第一个RadGrid中使用另一个RadGrid,但没有运气......也许我必须使用另一个不同的Telerik控件?

有人知道我怎么做到这一点?

这是我实施的一部分:

protected void myRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    this.myRadGrid.DataSource = this.dtListaDettagli;
    this.dtListaDettagli.PrimaryKey = new DataColumn[] { this.dtListaDettagli.Columns["key"] };
}


protected void myRadGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
        var listOfDetails = this.Session["listOfDetails"];
        //...
        var dtoTrav = (List<Detail_Type_N>) listOfDetails;
        PopolaUC(dtoTrav, userControl, e.Item.ItemIndex);
    }
}


private void PopolaUC<T>(List<T> data, UserControl uc, int index) where T : FlussiBaseDto
{
    // ...
    RadPane radPane = uc.FindControl("RadPane1") as RadPane;
    var properties = TypeDescriptor.GetProperties(typeof(Detail_Type_N));
    // ...
    var dettaglioSelected = (from x in data
                             where x.IdFlusso == idFlussoSelected && x.ProgDettaglio == progDettaglioSelected
                             select x).FirstOrDefault();

    HtmlTable htmlTable = new HtmlTable();
    htmlTable.ID = "DettaglioSinistro";
    var tRow = new HtmlTableRow();

    int i = 0;
    foreach (PropertyDescriptor prop in properties)
    {
        i++;
        if (i > 3) // organizza la sottotabella in 2 colonne
        {
            tRow = new HtmlTableRow();
            i = 1;
        }

        // Set label:
        HtmlTableCell tLabel = new HtmlTableCell();
        var stringInNormalCase = Regex.Replace(prop.Name, "(\\B[A-Z])", " $1");
        tLabel.InnerText = stringInNormalCase;
        tRow.Cells.Add(tLabel);

        // Set TextBox:
        HtmlTableCell tCell = new HtmlTableCell();
        // ...
        TextBox box = new TextBox();
        box.Text = Convert.ToString(prop.GetValue(detailSelected));
        box.ID = string.Format("my_{0}", prop.Name);
        tCell.Controls.Add(box);


        tRow.Cells.Add(tCell);
        htmlTable.Rows.Add(tRow);
    }
    radPane.Controls.Add(htmlTable);
}


protected void myRadGrid_UpdateCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem editedItem = e.Item as GridEditableItem;
    UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

    //Prepare new row to add it in the DataSource
    DataRow[] changedRows = this.dtListaDettagli.Select("key = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["key"]);

    // ... and then?

    catch (Exception ex)
    {
        changedRows[0].CancelEdit();

        Label lblError = new Label();
        lblError.Text = string.Format("Errore nell'aggiornamento movimento. Errore: {0} ", ex.Message);
        lblError.ForeColor = System.Drawing.Color.Red;
        RadGridIpa.Controls.Add(lblError);

        e.Canceled = true;
    }
}

1 回答

  • 0

    您无法动态生成TextBoxes和Labels .

    相反,您想使用Edit Form .

    例如,

    <telerik:RadGrid ID="RadGrid1" ...>
       <MasterTableView>
          ...
          <EditFormSettings>
              Place those textboxes and lables here.
          </EditFormSettings>
       </MasterTableView>
    </telerik:RadGrid>
    

相关问题