how to show my own error message?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Vincent
    Guest replied
    Re: how to show my own error message?

    Thanks
    "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgsch reef in
    bericht news:eDpcxOucIH A.3788@TK2MSFTN GP02.phx.gbl...
    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.DataS ource = SqlDataSource1
    try
    GridView1.DataB ind()
    catch
    ...
    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]


    >
    >
    "Vincent" <vi,@sd.cvwro te in message
    news:eukrN7tcIH A.4332@TK2MSFTN GP04.phx.gbl...
    >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_groe p1". 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:GridVie w ID="GridView1" runat="server">
    > <Columns>
    > <asp:TemplateFi eld>
    > <ItemTemplate >
    > <asp:LinkButt on ID="lb1" runat="server"
    > CommandArgument ="<%# Container.DataI temIndex %>"
    > CommandName="De lete">
    > </asp:LinkButton>
    > </ItemTemplate>
    > </asp:TemplateFie ld>
    >...
    >>
    >code-behind:
    >-----------
    >...
    >If e.CommandName = "Delete" Then
    > Try
    > Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
    >groupkey & "'"
    > Catch ex As Exception
    > label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
    >removed."
    > End Try
    >End If
    >>
    >>
    >Thanks
    >Vincent
    >>
    >T.
    >>
    >>
    >
    >

    Leave a comment:


  • Eliyahu Goldin
    Guest replied
    Re: how to show my own error message?

    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.DataS ource = SqlDataSource1
    try
    GridView1.DataB ind()
    catch
    ....
    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    "Vincent" <vi,@sd.cvwro te in message
    news:eukrN7tcIH A.4332@TK2MSFTN GP04.phx.gbl...
    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_groep 1". The conflict occurred in database "tennis", table
    "dbo.mytabl e", 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:TemplateFi eld>
    <ItemTemplate >
    <asp:LinkButt on ID="lb1" runat="server"
    CommandArgument ="<%# Container.DataI temIndex %>"
    CommandName="De lete">
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateFie ld>
    ...
    >
    code-behind:
    -----------
    ...
    If e.CommandName = "Delete" Then
    Try
    Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
    groupkey & "'"
    Catch ex As Exception
    label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
    removed."
    End Try
    End If
    >
    >
    Thanks
    Vincent
    >
    T.
    >
    >

    Leave a comment:


  • Vincent
    Guest started a topic how to show my own error message?

    how to show my own error message?

    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_groep 1". The conflict occurred in database "tennis", table
    "dbo.mytabl e", 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:TemplateFi eld>
    <ItemTemplate >
    <asp:LinkButt on ID="lb1" runat="server"
    CommandArgument ="<%# Container.DataI temIndex %>"
    CommandName="De lete">
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateFie ld>
    ....

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


    Thanks
    Vincent

    T.


Working...