Solved

edit delete programatically

Posted on 2009-03-31
4
319 Views
Last Modified: 2012-05-06
r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Edit&nbsp;Quantity />"
            r.Cells.Add(c)

            r.CssClass = "prgdata"
            c = New TableCell
            c.Text = "<input type=submit  value=Delete />"
            r.Cells.Add(c)

Visual studio 2003 1.1 frameworks

Yes I am not to sure on how to have a functional edit update and delete button programatically.
When I choose edit the Quantity should become a textbox and then I will update. Binded no problem, programatically a problem.

Dim sqlDR As SqlDataReader

        conn.Open()

        sqlDR = cmd.ExecuteReader(CommandBehavior.Default)

       
 

        ' While sqlDR.Read

        r = New TableRow

        r.CssClass = "HeaderCell"

        r.Style.Add("background", "339300")

        r.Style.Add("color", "FFFFFF")

        ' r.Style.Add("color", "Black")

        c = New TableCell

        c.ColumnSpan = 5
 

        c = New TableCell

        c.Text = "UPC code"

        r.Cells.Add(c)
 

        c = New TableCell

        c.Text = "Product Name"

        r.Cells.Add(c)
 

        c = New TableCell

        c.Text = "Quantity"

        r.Cells.Add(c)
 

        c = New TableCell

        c.Text = "Subtotal"

        r.Cells.Add(c)
 

        c = New TableCell

        'c.Text = "Case"

        r.Cells.Add(c)
 

        c = New TableCell

        'c.Text = "pallet"

        r.Cells.Add(c)
 

        'c = New TableCell

        'c.Text = "Trailer"

        'r.Cells.Add(c)
 

        Table1.Rows.Add(r)

        ' End While
 
 

        While sqlDR.Read
 

           

            r = New TableRow

            c = New TableCell
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = sqlDR("myItem")

            r.Cells.Add(c)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = sqlDR("Name")

            r.Cells.Add(c)

            Table1.Rows.Add(r)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = sqlDR("Quantity")

            r.Cells.Add(c)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = FormatPrice778(sqlDR("SubTotal"))

            r.Cells.Add(c)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = "<input type=submit  value=Edit&nbsp;Quantity />"

            r.Cells.Add(c)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = "<input type=submit  value=Delete />"

            r.Cells.Add(c)
 

            r.CssClass = "prgdata"

            c = New TableCell

            c.Text = "&nbsp;"

            r.Cells.Add(c)
 

           

            

            If sqlDR("BalanceQty") = "0" Then
 

                c.Text = "&nbsp;"
 

            Else

              

                Table1.Rows.Add(r)

                r = New TableRow

                c.Text = "&nbsp;"

                r.Cells.Add(c)
 

                c = New TableCell

                c.Text = "Cases"

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = sqlDR("BalanceQty")

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = FormatPrice778(sqlDR("CaseCost"))

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = "&nbsp;"

                r.Cells.Add(c)
 

            End If
 

            If sqlDR("TotalPalletQty") = "0" Then
 

                c.Text = "&nbsp;"
 

            Else

                Table1.Rows.Add(r)

                r = New TableRow

                c.Text = "&nbsp;"

                r.Cells.Add(c)
 

                c = New TableCell

                c.Text = "Pallet"

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = sqlDR("TotalPalletQty")

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = FormatPrice778(sqlDR("PalletCost"))

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = "&nbsp;" 'FormatPrice778(sqlDR("PalletCost"))

                r.Cells.Add(c)
 

            End If
 
 

            If sqlDR("TotalTrailerQty") = "0" Then

                c.Text = "&nbsp;"

            Else

                Table1.Rows.Add(r)

                r = New TableRow

                c.Text = "&nbsp;"

                r.Cells.Add(c)
 

                c = New TableCell

                c.Text = "Trailer"

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = sqlDR("TotalTrailerQty")

                r.Cells.Add(c)
 

                r.CssClass = "prgdata2"

                c = New TableCell

                c.Text = FormatPrice778(sqlDR("Trailer"))

                r.Cells.Add(c)

            End If

            Table1.Rows.Add(r)
 

           
 

        End While

Open in new window

0
Comment
Question by:sevensnake77
  • 2
4 Comments
 
LVL 9

Expert Comment

by:vavjeeva
Comment Utility
instead of adding each row in the buttion, you could use DATAGRID control and bind the data source along with the button..

you can use BoundColumn property for binding these values and use Template Column for adding button..

this links helps u to understand the core functionality of datagrid
http://www.codersource.net/asp_net_datagrid_part1_azam.html
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
Yes I know how to do that, I said that in my comment above, Thats why i was asking to do it programatically because I had no choice.
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
somthing like i have below.

 r.CssClass = "prgdata"

            c = New TableCell

            selectcol.ButtonType = ButtonColumnType.PushButton

            selectcol.Text = "Update"

            selectcol.CommandName = "Update"

            r.Cells.Add(c)

            'Table1.Rows.Add(selectcol)

            ' DataGrid1.Columns.Add(selectcol)

Open in new window

0
 
LVL 9

Accepted Solution

by:
AsishRaj earned 500 total points
Comment Utility
How about this

<%@ Page Language="C#" %>

<script runat="server">

    

 

    void btn_Click(object sender, EventArgs e)

    {

                 Response.Write(((sender)as Button).Text);

    }

 

    protected void Page_Load(object sender, EventArgs e)

    {

      HtmlTable myTable = new HtmlTable();

        for (int i = 0; i < 4; i++)

        {

                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();

                cell1.InnerText = "cell" + i;

                row.Controls.Add(cell1);

                HtmlTableCell cell2 = new HtmlTableCell();

                Button btn = new Button();

                btn.Text = "value" + i;

                btn.Click += new EventHandler(btn_Click);

                cell2.Controls.Add(btn);

                row.Controls.Add(cell2);

                myTable.Controls.Add(row);

            

        }

        PlaceHolder1.Controls.Add(myTable);

    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>untitled</title>

</head>

<body  >

    <form id="form1" runat="server" name="someForm" >

    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

   

    </form>

</body>

</html>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now