Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2005, 08:45 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to add aditional buttons to asp.net page?

Hi everybody.
I want add 2 coulums buttons with name of delete and penalties to my main code page that displays players records.
The delte button should deletes records and the the penealties button should displays the penalty record for that
perticuler player and allow me to edit it.

I be happy if some one help me how to accomplish this task. Thanks

-------------------------------------------------------------------------------------------------------
Here is my main code.It displays palyers records with only edit button on the right side of each record :

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">
    Dim objConnection As SqlConnection
    Dim myDataReader As SqlDataReader

    Sub Page_Load(Sender As Object, E As EventArgs)
        ' Set up our connection.
        objConnection = New SqlConnection("Data Source=(local);" _
            & "Initial Catalog=teniss2;User Id=web;Password=web;" _
            & "Connect Timeout=15;Network Library=dbmssocn;")

        LoadDataFromDB

        If Not IsPostBack Then
            DataBindGrid
        End If
    End Sub

    Sub LoadDataFromDB()
        Dim objCommand As SqlCommand

        ' Create new command object passing it our SQL query
        ' and telling it which connection to use.
        objCommand = New SqlCommand("SELECT * FROM Players;", objConnection)

        ' Open the connection, execute the command, and close the connection.
        objConnection.Open()
        myDataReader = objCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)
    End Sub

    Sub DataBindGrid()
        DBEditDataGrid.DataSource = myDataReader
        DBEditDataGrid.DataBind
    End Sub

    Sub DBEditDataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
        DBEditDataGrid.EditItemIndex = E.Item.ItemIndex
        DataBindGrid
    End Sub

    Sub DBEditDataGrid_Cancel(Sender As Object, E As DataGridCommandEventArgs)
        DBEditDataGrid.EditItemIndex = -1
        DataBindGrid
    End Sub

    Sub DBEditDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
        ' Since the textboxes are autogenerated we don't know their names,
        ' but we do know their positions.
        Dim intplayer As String = E.Item.Cells(0).Text
        Dim tbText1 As TextBox = E.Item.Cells(1).Controls(0)
        Dim tbText2 As TextBox = E.Item.Cells(2).Controls(0)
        Dim tbText3 As TextBox = E.Item.Cells(3).Controls(0)
                Dim tbText4 As TextBox = E.Item.Cells(4).Controls(0)
        Dim tbText5 As TextBox = E.Item.Cells(5).Controls(0)
        Dim tbText6 As TextBox = E.Item.Cells(6).Controls(0)
        Dim tbText7 As TextBox = E.Item.Cells(7).Controls(0)
                Dim tbText8 As TextBox = E.Item.Cells(8).Controls(0)
        Dim tbText9 As TextBox = E.Item.Cells(9).Controls(0)
        Dim tbText10 As TextBox = E.Item.Cells(10).Controls(0)
        Dim tbText11 As TextBox = E.Item.Cells(11).Controls(0)

        ' If you're not sure you've got the right values... check!
        Response.Write(intplayer)

        Response.Write(tbText1.Text)
        Response.Write(tbText2.Text)
        Response.Write(tbText3.Text)
                Response.Write(tbText4.Text)
                Response.Write(tbText5.Text)
                Response.Write(tbText6.Text)
                Response.Write(tbText7.Text)
                Response.Write(tbText8.Text)
                Response.Write(tbText9.Text)
                Response.Write(tbText10.Text)
                Response.Write(tbText11.Text)

        ' Update the appropriate record in our database.
        Dim objCommand As SqlCommand
        Dim strSQLQuery As String

        ' Build our update command.
             strSQLQuery = "UPDATE PLAYERS " _
                     & "SET NAME = '" & Replace(tbText1.Text, "'", "''") & "', " _
                     & "INITIALS = '" & tbText2.Text & "', " _
                     & "BIRTH_DATE = '" & Replace(tbText3.Text, "'", "''") & "', " _
                     & "************ = '" & tbText4.Text & "', " _
                     & "JOINED = '" & Replace(tbText5.Text, "'", "''") & "', " _
                     & "STREET = '" & tbText6.Text & "', " _
                     & "HOUSENO = '" & Replace(tbText7.Text, "'", "''") & "', " _
                     & "POSTCODE = '" & tbText8.Text & "', " _
                     & "TOWN = '" & Replace(tbText9.Text, "'", "''") & "', " _
                     & "PHONENO = '" & tbText10.Text & "', " _
                     & "LEAGUENO ='" & Replace(tbText11.Text, "'", "''") & "' " _
                     & "WHERE PLAYERNO = " & intplayer & ";"


        ' Again... if you're not sure you've got the right command built...
        ' you can always check!
        Response.Write(strSQLQuery)

        ' Create new command object passing it our SQL query
        ' and telling it which connection to use.
        objCommand = New SqlCommand(strSQLQuery, objConnection)

        ' Close our open DataReader
        myDataReader.Close

        Try
            ' Execute the command
            objConnection.Open()
            objCommand.ExecuteNonQuery()
            objConnection.Close()
        Catch Ex as Exception
            Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString() & "</p>" & vbCrLf)
            Response.Write("<p>Most likely you tried to enter data that was inappropriate.</p>" & vbCrLf)
            Response.Write("[list]" & vbCrLf)
            Response.Write("<li>The text field is limited to 10 characters at the database level.</li>" & vbCrLf)
            Response.Write("<li>The integer field is a smallint... no text and only values from -32768 to 32767!</li>" & vbCrLf)
            Response.Write("<li>The datetime field must contain a string that can be converted to a valid Date / Time</li>" & vbCrLf)
            Response.Write("</ul>" & vbCrLf)
        Finally
            objConnection.Close()
        End Try

        ' Refresh our copy of the data
        LoadDataFromDB

        ' Reset our current edit item and rebind the grid
        DBEditDataGrid.EditItemIndex = -1
        DataBindGrid
    End Sub
</script>

<html>
<head>
<title>Database Edit</title>
</head>
<body>

<form runat="server">

<asp:DataGrid id="DBEditDataGrid" runat="server"
    BorderWidth = "1" CellSpacing = "2" CellPadding = "2"
    HeaderStyle-Font-Bold = "True"

     OnEditCommand = "DBEditDataGrid_Edit"
    OnCancelCommand = "DBEditDataGrid_Cancel"
    OnUpdateCommand = "DBEditDataGrid_Update"

    AutoGenerateColumns = "False"
>
    <Columns>

        <asp:BoundColumn HeaderText="PLAYERNO" DataField="PLAYERNO" ReadOnly="True" />
        <asp:BoundColumn HeaderText="NAME" DataField="NAME" />
        <asp:BoundColumn HeaderText="INITIALS" DataField="INITIALS" />
        <asp:BoundColumn HeaderText="BIRTH_DATE" DataField="BIRTH_DATE" />
                <asp:BoundColumn HeaderText="************" DataField="************" />
                <asp:BoundColumn HeaderText="JOINED" DataField="JOINED" />
                <asp:BoundColumn HeaderText="STREET" DataField="STREET" />
                <asp:BoundColumn HeaderText="HOUSENO" DataField="HOUSENO" />
                <asp:BoundColumn HeaderText="POSTCODE" DataField="POSTCODE" />
                <asp:BoundColumn HeaderText="TOWN" DataField="TOWN" />
                <asp:BoundColumn HeaderText="PHONENO" DataField="PHONENO" />
                <asp:BoundColumn HeaderText="LEAGUENO" DataField="LEAGUENO" />

        <asp:EditCommandColumn
            HeaderText = "Edit"
            EditText = "Edit"
            CancelText = "Cancel"
            UpdateText = "Update"
        />
    </Columns>
</asp:DataGrid>

</form>



<p>
Click <a href="./back.aspx">here</a>
to return back
</p>

</body>
</html>

 
Old May 1st, 2005, 08:46 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the sub code for Delete i want to add this sub to the above page so i have the delete
and edit records button in the same page:

Sub DBDelDataGrid_Delete(source As Object, E As DataGridCommandEventArgs)
        Dim objCommand As SqlCommand
        Dim strSQLQuery As String

        ' Our delete command using the index field from our DataGrid.
        ' I should probably make this a parameter and pass it in
        ' like I do in the AddNewRecord() Sub, but it just goes to
        ' show that you can do things whatever way you're more comfortable with.
        strSQLQuery = "DELETE FROM PLAYERS WHERE PLAYERNO=" & DBDelDataGrid.DataKeys(E.Item.ItemIndex) & ";"

        ' In case something goes wrong you can check the SQL...
        'Response.Write(strSQLQuery)

        ' Create new command object passing it our SQL delete
        ' and telling it which connection to use.
        objCommand = New SqlCommand(strSQLQuery, objConnection)

        ' Open the connection, execute the command, and close the connection.
        objConnection.Open()
        objCommand.ExecuteNonQuery()
        objConnection.Close()

        ' Record is now deleted... you should add appropriate error
        ' checking and handling, but we've left it out simply for
        ' clarity and brevity. Either that or I was just too lazy
        ' to write it... I don't recall! ;)

        ' Refresh our Datagrid to show the record is gone
          LoadDataFromDB



    End Sub

 
Old May 1st, 2005, 08:46 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is seperate page that only displays penalties table records .I want pass this page
the palyer number from the main page to allow me edit penalites records.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">
    Dim objConnection As SqlConnection
    Dim myDataReader As SqlDataReader

    Sub Page_Load(Sender As Object, E As EventArgs)
        ' Set up our connection.
        objConnection = New SqlConnection("Data Source=(local);" _
            & "Initial Catalog=teniss2;User Id=web;Password=web;" _
            & "Connect Timeout=15;Network Library=dbmssocn;")

        LoadDataFromDB

        If Not IsPostBack Then
            DataBindGrid
        End If
    End Sub

    Sub LoadDataFromDB()
        Dim objCommand As SqlCommand

        ' Create new command object passing it our SQL query
        ' and telling it which connection to use.
        objCommand = New SqlCommand("SELECT * FROM penalties;", objConnection)

        ' Open the connection, execute the command, and close the connection.
        objConnection.Open()
        myDataReader = objCommand.ExecuteReader(System.Data.CommandBehavi or.CloseConnection)
    End Sub

    Sub DataBindGrid()
        DBEditDataGrid.DataSource = myDataReader
        DBEditDataGrid.DataBind
    End Sub

    Sub DBEditDataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
        DBEditDataGrid.EditItemIndex = E.Item.ItemIndex
        DataBindGrid
    End Sub

    Sub DBEditDataGrid_Cancel(Sender As Object, E As DataGridCommandEventArgs)
        DBEditDataGrid.EditItemIndex = -1
        DataBindGrid
    End Sub

    Sub DBEditDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
        ' Since the textboxes are autogenerated we don't know their names,
        ' but we do know their positions.
        Dim intplayer As String = E.Item.Cells(0).Text
        Dim tbText1 As TextBox = E.Item.Cells(1).Controls(0)
        Dim tbText2 As TextBox = E.Item.Cells(2).Controls(0)
        Dim tbText3 As TextBox = E.Item.Cells(3).Controls(0)


        ' If you're not sure you've got the right values... check!
        Response.Write(intplayer)
            Response.Write("<BR>")
                Response.Write(tbText1.Text)
        Response.Write("<BR>")
        Response.Write(tbText2.Text)
                Response.Write("<BR>")
        Response.Write(tbText3.Text)
                Response.Write("<BR>")



        ' Update the appropriate record in our database.
        Dim objCommand As SqlCommand
        Dim strSQLQuery As String

        ' Build our update command.
             strSQLQuery = "UPDATE PENALTIES " _
                     & "SET PAYMENTNO = '" & Replace(tbText1.Text, "'", "''") & "', " _
                     & "PEN_DATE = '" & tbText2.Text & "', " _
                     & "AMOUNT = '" & Replace(tbText3.Text, "'", "''") & "' " _
                     & "WHERE PLAYERNO = " & intplayer & ";"


        ' Again... if you're not sure you've got the right command built...
        ' you can always check!
                Response.Write("<BR>")
        Response.Write(strSQLQuery)

        ' Create new command object passing it our SQL query
        ' and telling it which connection to use.
        objCommand = New SqlCommand(strSQLQuery, objConnection)

        ' Close our open DataReader
        myDataReader.Close

        Try
            ' Execute the command
            objConnection.Open()
            objCommand.ExecuteNonQuery()
            objConnection.Close()
        Catch Ex as Exception
            Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString() & "</p>" & vbCrLf)
            Response.Write("<p>Most likely you tried to enter data that was inappropriate.</p>" & vbCrLf)
            Response.Write("[list]" & vbCrLf)
            Response.Write("<li>The text field is limited to 10 characters at the database level.</li>" & vbCrLf)
            Response.Write("<li>The integer field is a smallint... no text and only values from -32768 to 32767!</li>" & vbCrLf)
            Response.Write("<li>The datetime field must contain a string that can be converted to a valid Date / Time</li>" & vbCrLf)
            Response.Write("</ul>" & vbCrLf)
        Finally
            objConnection.Close()
        End Try

        ' Refresh our copy of the data
        LoadDataFromDB

        ' Reset our current edit item and rebind the grid
        DBEditDataGrid.EditItemIndex = -1
        DataBindGrid
    End Sub
</script>

<html>
<head>
<title>ASP.NET Database Edit Sample</title>
</head>
<body>

<form runat="server">

<asp:DataGrid id="DBEditDataGrid" runat="server"
    BorderWidth = "1" CellSpacing = "2" CellPadding = "2"
    HeaderStyle-Font-Bold = "True"

     OnEditCommand = "DBEditDataGrid_Edit"
    OnCancelCommand = "DBEditDataGrid_Cancel"
    OnUpdateCommand = "DBEditDataGrid_Update"

    AutoGenerateColumns = "False"
>
    <Columns>

            <asp:BoundColumn HeaderText="PLAYERNO" DataField="PLAYERNO" ReadOnly="True" />
        <asp:BoundColumn HeaderText="PAYMENTNO" DataField="PAYMENTNO" />
        <asp:BoundColumn HeaderText="PEN_DATE" DataField="PEN_DATE" />
                <asp:BoundColumn HeaderText="AMOUNT" DataField="AMOUNT" />


        <asp:EditCommandColumn
            HeaderText = "Edit"
            EditText = "Edit"
            CancelText = "Cancel"
            UpdateText = "Update"
        />
    </Columns>
</asp:DataGrid>

</form>



<p>
Click <a href="./back.aspx">here</a>
to return back
</p>

</body>
</html>




 
Old May 2nd, 2005, 12:00 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

I think i understand that you want to pass something from one page to another. You could use a querystring. Umm something like:

you pass the querystring in the url... ie http://www.yourdomain.com?PlayerID=1 you can then pick this up in the page by using Request.Querystring("PlayerID").

Anyone else think thats right. Trying to help out round here now as asked loads of questions so its time to return.

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
 
Old May 3rd, 2005, 06:23 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

You can also create a user control and put the code to show the players list

Regards
Ganesh
 
Old May 3rd, 2005, 07:17 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by RPG SEARCH
 I think i understand that you want to pass something from one page to another. You could use a querystring. Umm something like:

you pass the querystring in the url... ie http://www.yourdomain.com?PlayerID=1 you can then pick this up in the page by using Request.Querystring("PlayerID").

Anyone else think thats right. Trying to help out round here now as asked loads of questions so its time to return.

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
Thank u for u reply. Well i be happy if u show me how to create that button that passes the playerno to the next page since i am new to this .net .Thanks

 
Old May 3rd, 2005, 07:18 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by r_ganesh76
 You can also create a user control and put the code to show the players list

Regards
Ganesh
thanks ganesh for u reply. Could u show me how to create that user controle .Thanks

 
Old May 4th, 2005, 01:58 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

you can create user controls just like you create an asp page. Once you create the user control, you can drag it from the solutions explorer to your page. You can also add some properties to the user control. in the event which you want to display the players list, you can hide the rest of the items in the page and then show up the user control.


Regards
Ganesh
 
Old May 4th, 2005, 02:00 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

if you are new to creating user controls and properties some of these links might be helpful.

http://www.asp101.com/lessons/usercontrols.asp
http://www.15seconds.com/issue/020319.htm

Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add a hit counter in asp.net page narayannayakmca ASP.NET 1.0 and 1.1 Basics 1 January 3rd, 2007 01:11 PM
How to add color dialog in asp.net page? param99 ASP.NET 1.0 and 1.1 Professional 1 November 20th, 2006 03:15 PM
Add asp.net page to asp project debdemoe Classic ASP Basics 0 August 17th, 2005 12:28 PM
2 buttons going to same ASP page chrscote Classic ASP Basics 1 June 1st, 2005 03:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.