Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to show my own error message?

Reply
Thread Tools

how to show my own error message?

 
 
Vincent
Guest
Posts: n/a
 
      02-19-2008
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.


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-19-2008
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
....
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Vincent" <vi,@sd.cv> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Vincent
Guest
Posts: n/a
 
      02-19-2008
Thanks
"Eliyahu Goldin" <(E-Mail Removed)> schreef in
bericht news:(E-Mail Removed)...
> 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
> ...
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "Vincent" <vi,@sd.cv> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using own classloader inside J2EE to load and unload own classes. Stefan Siegl Java 1 07-02-2013 05:05 AM
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
[ANN] Slide Show (S9) Gem V0.6 - New and Improved Support for UsingYour Own Slide Show Templates Gerald Bauer Ruby 0 08-26-2008 08:12 PM
Allowing access to my own computers within my own network =?Utf-8?B?VHJldm9y?= Wireless Networking 2 07-20-2006 09:05 PM
I have built my own (simple) thread manager [TM], but just found java 5 has its own. Saverio M. Java 0 07-03-2006 08:52 AM



Advertisments