Solved

edit delete programatically

Posted on 2009-03-31
4
323 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
ID: 24031628
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
ID: 24031764
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
ID: 24032517
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
ID: 24035005
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

776 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