c# - How to add exception handling to SqlDataSource.UpdateCommand -


we have radgrid automatically updated sqldatasource.updatecommand. when edit column(s) , click on "update" table updated correctly updatecommand in markup.

it looks this:

<telerik:radgrid id="radgrid" datasourceid="sqldatasource1" runat="server" allowautomaticupdates="true" > <mastertableview autogeneratecolumns="false" datakeynames="city" commanditemdisplay="top"  allowautomaticupdates="true">         <columns>             <telerik:grideditcommandcolumn buttontype="imagebutton" uniquename="editcommandcolumn">             </telerik:grideditcommandcolumn>             <telerik:gridboundcolumn datafield="city" headertext="city" readonly="true" sortexpression="city"                 uniquename="city" >             </telerik:gridboundcolumn>             <telerik:gridboundcolumn datafield="prefix" headertext="prefix" uniquename="prefix">             </telerik:gridboundcolumn>             <telerik:gridboundcolumn datafield="sector" headertext="sector" uniquename="sector">             </telerik:gridboundcolumn>         </columns>         </mastertableview> </telerik:radgrid> <asp:sqldatasource id="sqldatasource1" connectionstring="<%$ connectionstrings:rf-prconnectionstring %>" selectcommand="select statement" runat="server" updatecommand= "update statement"> <updateparameters>     <asp:parameter name="name" type="string" />     <asp:parameter name="sector" type="string" /> </updateparameters> </asp:sqldatasource> 

but let's update generates exception in table (ie. tried update int varchar, violates key, etc). there way can add try...catch sqldatasource.updatecommand? wouldn't know how since there's no code behind update, done through sqldatasource.

very simple solution: need handle onrowupdated event.

protected void gridview_rowupdated(object sender, gridviewupdatedeventargs e) {     if (e.exception != null)     {         //show error message         e.exceptionhandled = true;     } } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -