|
Rank: Newbie Groups: Member
Joined: 8/26/2010 Posts: 3
|
Hello Is there anyway to show a message when the database.ExecuteNonQuery() had error?
for e.g
protected void Grid1_ItemDeleted(object sender, EO.Web.GridItemEventArgs e) { try { StringBuilder sql = new StringBuilder(); sql.Append("delete from product "); sql.Append(" where product_id=@product_id"); string connStr = ConfigurationManager.ConnectionStrings["mySqlServer"].ToString(); SqlConnection sqlConn = new SqlConnection(connStr); SqlCommand dbCmd; dbCmd = new SqlCommand(sql.ToString(), sqlConn); dbCmd.Parameters.AddWithValue("@product_id", e.Item.Cells[2].Value.ToString()); sqlConn.Open(); dbCmd.ExecuteNonQuery(); sqlConn.Close(); dbCmd.Dispose();
} catch (Exception ex) { e.Item.Deleted = false; } }
I want to show the exception to user, but I CANT! I tried many ways to , but because it a AJAX method, i cant render javascript or change other controls.... Please help me with this . thanks a lot!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Can you explain what you mean by "because it is an AJAX method"? How you use AJAX in the page?
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/26/2010 Posts: 3
|
ah.. sorry, i guess it's a AJAX method bcuz i cant change other contols(like textbox.text)
Grid1_ItemDeleted will be triggered after grid.deleteItem(itemIndex).
function OnItemDelete(grid, itemIndex, colIndex, commandName) { //Ask user to confirm the delete if (window.confirm("Are your sure you want to delete this record?")) { grid.deleteItem(itemIndex);
} }
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
No. The Grid doesn't do anything AJAX as long as the Grid's RunningMode is not "Callback". So the reason that you can't change other controls must be something else. Also you may want to confirm whether Grid1_ItemDeleted has indeed been called. As a test, I would suggest you to try the Grid in a blank page without anything else (not even master page). That should help you to isolate the issue and points you to the right direction.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/26/2010 Posts: 3
|
Hello , My Grid's runningMode is Callback
Code: HTML/ASPX
<eo:Grid runat="server" id="Grid1" BorderColor="#828790" BorderWidth="1px" GridLines="Both"
FixedColumnCount="1" ColumnHeaderDescImage="00050205" GridLineColor="240, 240, 240" Width="100%"
IsCallbackByMe="False" ItemHeight="19" ColumnHeaderAscImage="00050204" ColumnHeaderHeight="24"
Height="410px" Font-Size="8.75pt" Font-Names="Tahoma" ColumnHeaderDividerImage="00050203"
AllowPaging="True" BackColor="White"
Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False"
RunningMode="Callback" ClientSideOnItemCommand="OnItemDelete"
onitemcommand="Grid1_ItemCommand" ClientSideAfterEditItem="update_total"
PageSize="18" ClientSideBeforeEditItem="beforeEdit"
oncolumnsort="Grid1_ColumnSort"
onpageindexchanged="Grid1_PageIndexChanged" onitemdeleted="Grid1_ItemDeleted"
>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Even in Callback mode the Grid would not trigger server side Grid1_ItemDeleted immediately. That event is triggered when the page posts back, which is usually not the Grid. In Callback mode the Grid triggers AJAX call immediately when you page or sort the Grid, which has nothing to do with your item delete.
It will be hard for us to tell you exactly what to do without seeing your code. So please isolate the problem into a test page and post the test page so that we can see what you are trying to do. You can try to remove all DB related code and fill the grid with dummy data so that we can run the code here if necessary.
Thanks!
|
|