Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's a little trickier when you want to put it into edit mode based on data. You tell the datagrid which of it's displayed rows is editable, not which data you want to be editable, so you'll need to go through each of the rows in the grid, see if it matches the id, and set the EditItemIndex to the appropriate value and rebind.</p> <p>You could look at the source data and get the row number from that before you bind, but then you may have problems with paging, sorting etc.</p> <p>It's a bit messy having to rebind the grid, but I can't think of a better way off the top of my head.</p> <pre><code>public partial class _Default : System.Web.UI.Page { private DataTable GetData() { DataTable tTable = new DataTable(); tTable.Columns.Add(new DataColumn("Column1", typeof(int))); tTable.Columns.Add(new DataColumn("Column2", typeof(string))); DataRow tRow = tTable.NewRow(); tRow["Column1"] = 1; tRow["Column2"] = "Test1"; tTable.Rows.Add(tRow); tRow = tTable.NewRow(); tRow["Column1"] = 2; tRow["Column2"] = "Test2"; tTable.Rows.Add(tRow); tRow = tTable.NewRow(); tRow["Column1"] = 3; tRow["Column2"] = "Test3"; tTable.Rows.Add(tRow); tRow = tTable.NewRow(); tRow["Column1"] = 4; tRow["Column2"] = "Test4"; tTable.Rows.Add(tRow); tRow = tTable.NewRow(); tRow["Column1"] = 5; tRow["Column2"] = "Test5"; tTable.Rows.Add(tRow); return tTable; } private void BindData() { DataTable tTable = GetData(); TestGrid.DataSource = tTable; TestGrid.DataBind(); if (!String.IsNullOrEmpty(Request.QueryString["edit"])) { foreach (DataGridItem tRow in TestGrid.Items) { if (tRow.Cells[0].Text == Request.QueryString["edit"]) TestGrid.EditItemIndex = tRow.ItemIndex; } TestGrid.DataBind(); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) BindData(); } } </code></pre> <p>You should be able to fire that up (with a datagrid added to the ASPX obviously) then put ?edit= on the end of the URL to get it to open the relevent entry in edit mode.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload