Note that there are some explanatory texts on larger screens.

plurals
  1. POError on GridView postback
    primarykey
    data
    text
    <p>I have two sites in a web application. What I want to do is update the list from Site A from a web part in Site B using a button. </p> <p>The problem is that if I don't use <code>Page.IsPostBack</code>, the page throws an unhandled exception when the button is clicked, BUT, the list in Site A is updated. But if I use <code>Page.IsPostBack</code>, I don't get the exception but the process doesn't push through; as a matter of fact, it doesn't even proceed to the eventhandler when the button is clicked.</p> <pre><code>if (!Page.IsPostBack) { using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { SPQuery query = new SPQuery(); query.Query = @"Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name='Title' /&gt;&lt;/OrderBy&gt;&lt;Query&gt;"; query.ViewAttributes = "&lt;FieldRef Name='Title' /&gt;"; query.ViewFields = string.Concat( "&lt;FieldRef Name='Title' /&gt;", "&lt;FieldRef Name='Status' /&gt;", "&lt;FieldRef Name='Severity' /&gt;", "&lt;FieldRef Name='Comment' /&gt;"); query.ViewFieldsOnly = true; showGrid = new GridView(); this.Controls.Add(showGrid); SPList list = SPContext.Current.Site.RootWeb.Lists["Ticket List"]; DataTable dt = new DataTable(); ButtonField approveBtn = new ButtonField(); approveBtn.ButtonType = ButtonType.Button; approveBtn.CommandName = "Update"; approveBtn.Text = "Approve"; showGrid.Columns.Add(approveBtn); dt = list.Items.GetDataTable().Copy(); dt = list.GetItems(query).GetDataTable(); showGrid.DataSource = dt; showGrid.DataBind(); showGrid.RowCommand += new GridViewCommandEventHandler(inventoryGridView_RowCommand); } } </code></pre> <p>Eventhandler</p> <pre><code>if (e.CommandName == "Update") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = showGrid.Rows[index]; using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb Web = site.OpenWeb()) { Web.AllowUnsafeUpdates = true; // Open List SPList list = SPContext.Current.Site.RootWeb.Lists["Ticket List"]; SPListItem _listItem = list.Items[row.RowIndex]; _listItem["Status"] = "Approved"; _listItem.Update(); Web.AllowUnsafeUpdates = false; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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