Click here to Skip to main content
15,897,704 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionASP RichTextBox Pin
Socheat.Net25-Apr-07 0:44
Socheat.Net25-Apr-07 0:44 
AnswerRe: ASP RichTextBox Pin
Sathesh Sakthivel25-Apr-07 0:59
Sathesh Sakthivel25-Apr-07 0:59 
AnswerRe: ASP RichTextBox Pin
Haissam25-Apr-07 10:01
Haissam25-Apr-07 10:01 
QuestionHow to print the items in a datagrid in ASP .Net Pin
Balagurunathan S25-Apr-07 0:16
Balagurunathan S25-Apr-07 0:16 
AnswerRe: How to print the items in a datagrid in ASP .Net Pin
N a v a n e e t h25-Apr-07 1:06
N a v a n e e t h25-Apr-07 1:06 
AnswerRe: How to print the items in a datagrid in ASP .Net Pin
Arun.Immanuel25-Apr-07 1:11
Arun.Immanuel25-Apr-07 1:11 
AnswerRe: How to print the items in a datagrid in ASP .Net Pin
Sathesh Sakthivel25-Apr-07 1:37
Sathesh Sakthivel25-Apr-07 1:37 
QuestionDeleting from a gridview control [modified] Pin
Senseicads25-Apr-07 0:11
Senseicads25-Apr-07 0:11 
Hi
I am a long time powerbuilder developer who has recently started a new job working with asp.net and vb. I am currently using a grid view to display a list of users. I need to be able to delete an unused user from the table. ie one that has had nothing in the referenced table assigned to him. I have set up the auto command button thingy to delete the user in the current row My database works ace with the constraints set up correctly. If I attempt to delete a user that has been referenced elsewhere I get a lovely asp error page saying that it fails the constraint check, and if he hasn't been referenced anywhere he gets deleted. However I want to be able to handle the error so that I get something more meaningful for the user. I have thought about two ways of doing this, and I am a bit stuck on getting either way to work.

The first way I thought of was to place in the rowdeleting event of the gridview a check to say if there exists in the referenced table an instance of the userID then cancel the event using e.cancel(). This would work ace except that I can't for the life of me find the command to reference which row is clicked. Also this means another call to the database which prob isn't so great.

The other way I thought of would be to catch the constraint exception coming from the database. However I can't find where to put this. I mean I assume its a try catch somewhere, but there is no event for the delete being run, its either rowdeleting or rowdeleted. So not sure of the way this should be handled, any help would be most appreciated. I realise this is prob a trivial explanation but there doesn't seem to be a lot of info about it around.

Cheers

Ian Caddick


-- modified at 8:38 Wednesday 25th April, 2007
Ok then think I have managed to solve the problem I have used option one and found out how to return to the row number clicked. It might have seemed like a bit of a trivial option but after much faffing around with dictionary things discovered the datakey object! Why oh why is there not a lot of help around the net on this? This is what I came up with in the end...
<br />
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting<br />
<br />
        Dim index = Integer.Parse(e.RowIndex)<br />
        Dim dk As DataKey<br />
<br />
        dk = GridView1.DataKeys.Item(index)<br />
<br />
        Dim iOpID = dk.Value<br />
<br />
        ' Check if the User Can be deleted if he can enable the delete button.<br />
        Dim connectionString = sqlSubSystem.ConnectionString<br />
        Dim SqlConnection As SqlConnection<br />
        SqlConnection = New SqlConnection(connectionString)<br />
        Dim Command As SqlCommand<br />
<br />
        Dim queryString As String = "SELECT count(subsystemID) FROM dbo.supportcall where [subsystemID] = " & iOpID.ToString()<br />
        Command = New SqlCommand(queryString, SqlConnection)<br />
<br />
        SqlConnection.Open()<br />
        Dim i<br />
        i = Command.ExecuteScalar()<br />
        SqlConnection.Dispose()<br />
        Command.Dispose()<br />
<br />
        If i > 0 Then<br />
            lblError.Text = "Cannot Delete as Subsystem already in use."<br />
            lblError.Visible = True<br />
            e.Cancel = True<br />
        Else<br />
<br />
        End If<br />
<br />
<br />
    End Sub


I would still like to know how to do it by catching the constraints exception tho, if anyone can shed any light on that.

Cheers

Cads
QuestionHow to Install AJAX Control Tool Kit? Pin
Jay_se24-Apr-07 23:52
Jay_se24-Apr-07 23:52 
AnswerRe: How to Install AJAX Control Tool Kit? Pin
szukuro24-Apr-07 23:59
szukuro24-Apr-07 23:59 
GeneralRe: How to Install AJAX Control Tool Kit? Pin
Jay_se25-Apr-07 0:39
Jay_se25-Apr-07 0:39 
GeneralRe: How to Install AJAX Control Tool Kit? Pin
szukuro25-Apr-07 1:08
szukuro25-Apr-07 1:08 
JokeRe: How to Install AJAX Control Tool Kit? Pin
Jay_se25-Apr-07 1:17
Jay_se25-Apr-07 1:17 
QuestionView state Pin
yaminilatha24-Apr-07 23:51
yaminilatha24-Apr-07 23:51 
AnswerRe: View state Pin
_AK_24-Apr-07 23:58
_AK_24-Apr-07 23:58 
AnswerRe: View state Pin
Jay_se24-Apr-07 23:58
Jay_se24-Apr-07 23:58 
AnswerRe: View state Pin
great gs24-Apr-07 23:58
great gs24-Apr-07 23:58 
AnswerRe: View state Pin
rama charan25-Apr-07 0:02
rama charan25-Apr-07 0:02 
GeneralRe: View state Pin
yaminilatha25-Apr-07 0:07
yaminilatha25-Apr-07 0:07 
QuestionConnect to MS Access from different domain Pin
Socheat.Net24-Apr-07 23:43
Socheat.Net24-Apr-07 23:43 
QuestionGridview Pin
A kamath24-Apr-07 23:41
A kamath24-Apr-07 23:41 
AnswerRe: Gridview Pin
_AK_24-Apr-07 23:46
_AK_24-Apr-07 23:46 
GeneralRe: Gridview Pin
A kamath24-Apr-07 23:50
A kamath24-Apr-07 23:50 
GeneralRe: Gridview Pin
_AK_24-Apr-07 23:56
_AK_24-Apr-07 23:56 
AnswerRe: Gridview Pin
RichardGrimmer26-Apr-07 5:39
RichardGrimmer26-Apr-07 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.