Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

how to show my own error message?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vincent - 19 Feb 2008 10:04 GMT
Hi,

There are two related tables: one called 'group' and the other 'items'. Each
item belongs to a group. The table 'group' is shown in a gridview with a
linkbutton for deleting.

When an user tries to delete a group which still contains items, he gets the
message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groep1". The conflict occurred in database "tennis", table
"dbo.mytable", column 'groupna'.
The statement has been terminated. "

I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.

aspx file:
----------
<asp:GridView ID="GridView1" runat="server">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="lb1" runat="server"
    CommandArgument="<%# Container.DataItemIndex %>"
    CommandName="Delete">
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
...

code-behind:
-----------
...
If e.CommandName = "Delete" Then
  Try
  Me.SqlDataSource1.DeleteCommand = "delete from groep WHERE groepnr='" &
groupkey & "'"
  Catch ex As Exception
  label1.Text = "Group '" & Server.HtmlEncode(groupkey) & "' cannot be
removed."
  End Try
End If

Thanks
Vincent

T.
Eliyahu Goldin - 19 Feb 2008 10:38 GMT
You need to try-catch the databind operation. With the declarative
databinding it is a bit tricky. It will be simpler just to use regular
databinding, with the DataSource property rather that with the DataSourceID:

GridView1.DataSource = SqlDataSource1
try
GridView1.DataBind()
catch
...
Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hi,
>
[quoted text clipped - 43 lines]
>
> T.
Vincent - 19 Feb 2008 20:10 GMT
Thanks
> You need to try-catch the databind operation. With the declarative
> databinding it is a bit tricky. It will be simpler just to use regular
[quoted text clipped - 53 lines]
>>
>> T.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.